JavaScript function with default parameter | Set Default Parameters example

Assign a default value to the parameter is called a function with the default parameter in JavaScript. A default value is required if no value or undefined is a passed-in function.

JavaScript function with default parameter Example

Let see HTML example code of How to set default parameters in JS function.

Default value for b is 1, will use this value if no value passed for it.


JavaScript function with default parameter

Another way to set default values

In JavaScript, you can call a function (even if it has parameters) without argument.


JavaScript Set Default Parameters example

Q: What will happen if no value passed for the parameter and no default value set?

Answer: If a function in JavaScript is called with any missing arguments the missing values are set to undefined.


Not default parameter values in the function declaration

Do comment if you have any doubts and suggestion on this JS function topic.

Note: All JS Examples codes are tested on the Firefox browser and the Chrome browser.
OS: Windows 10
Code: HTML 5 Version

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.