optional function parameter javascript code example
Example 1: javascript default function parameter value
function multiply(a, b) {
b = (typeof b !== 'undefined') ? b : 1
return a * b
}
Example 2: optional function parameter javascript
function check(a, b = 0) {
document.write("Value of a is: " + a +
" Value of b is: " + b +
"<br>");
}
check(9, 10);
check(1);