JavaScript | Function call example with given number of arguments and less arguments

JavaScript function call example: Here, we are going to learn what happens/prints when a function is called with less number of arguments or no arguments?
Submitted by Pankaj Singh, on October 12, 2018

Example:

Here, we are defining a JavaScript function named show() which has two arguments id and name and calling the function, with 1) both arguments, 2) one argument and 3) no argument.

Code:

<html lang="en">
<head>
    <script>
        function show(id,name){
            document.write("Your name is <b>"+name+"</b> and your id is <b>"+id+"</b><br /><br />");
        }
    </script>
</head>
<body>
    <script>
        show(12,"pankaj");
        show(12);
        show();
    </script>
</body>
</html>

Output

Js code output

JavaScript Examples »



ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT


Comments and Discussions!




Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.