function with optional parameter javascript code example
Example 1: js unspecified parameters
function my_log(...args) {
console.log(args);
console.log(...args);
}
Example 2: javascript optional parameters
const myFunction = (str, id=0) => {
console.log(str, id)
}
myFunction("Hello Grepper")
myFunction("HG", 10)
Example 3: 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);
Example 4: variable defaults javascript es6
let variableToSet = checkedValue || defaultValue;