default value in javascript code example
Example 1: javascript constructor default parameter
function greet(name, greeting, message = greeting + ' ' + name) {
return [name, greeting, message]
}
greet('David', 'Hi')
greet('David', 'Hi', 'Happy Birthday!')
Example 2: javascript default parameters
function multiply(a, b = 1) {
return a * b;
}
Example 3: default in javascript
const greet = (message = 'Hello World!') => console.log(message);
greet();
greet('Hello! Does this answer your question?')
Example 4: variable defaults javascript es6
let variableToSet = checkedValue || defaultValue;