![]() ![]() In the third calling of the function, we have passed a (' '), which means it will console log the string value of the parameter.In the second calling of the function, we have passed undefined as the parameter value, which means the function will console log the default value here also.In the first invocation of the function, we have called the function with no passing of the value, so it will console log out the default value only.We have created a function where we have provided a default value to the function's parameter, and in the calling of the function, we have invoked the function four times.Let's see some more examples to better understand the concept:Įxample 1: Passing undefined as the parameterĮxample2() // outputs number and The value of a is: 5Įxample2(undefined) // output gives as 1Įxample2('') // outputs string and the value of a is:Įxample2(null) // outputs object and the value of a: null Few examples of JavaScript Default Parameters Let's see some more examples to understand the working of the default parameters more efficiently. As a result, you might now be able to understand the working and use of the default parameters.For the last invoking of the function, we have passed two values for both the parameters, and so the default values will not be passed for any of the parameters because values are being supplied. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |