JavaScript function default value

Setting up JavaScript function parameters default value is allowed to initialize variables with default values if no values or undefined are passed into the function.

Default parameters allow us to initialize functions with default values.

Simple example code of Set a default parameter value for a JavaScript function.

Example of set function default value JavaScript

In JavaScript, you can call a function without parameters.

So you can add default values like this:

In the example, we set the default value of A and B as 10 and 20. If you pass the value then it will show in the alert box, otherwise, it will show 10 and 20.

Complete code


JavaScript function default value

Do comment if you have any doubts and suggestions on this topic.

Note: The All JS Examples codes are tested on the Safari browser (Version 12.0.2) and Chrome.
OS: macOS 10.14 Mojave
Code: HTML 5 Version

Leave a Reply

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