layout: post title: Javascript Default date: —
Javascript Default
*In JavaScript, parameters of functions default to undefined.
*However, in some situations it might be useful to set a different default value.
*This is where default parameters can help.
*In the past, the general strategy for setting defaults was to test parameter values in the body of the function,
-
and assign a value if they are undefined. If in the following example,
-
no value is provided for b in the call,
its value would be undefined when evaluating ab and the call to multiply would have returned NaN.
- However, this is caught with the second line in this example: