Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
This code snippet is used in Default Parameters in ES6 JavaScript Tutorial for SFDC Stop
// * Default parameters in ES6 functions
// * Default values before ES6
// function add(a, b) {
// b = b ? b : 2;
// console.log(a+b);
// }
// * Default value using ES6 syntax
function add(a, b = 2) {
console.log(a+b);
}
add(3);
// * Default value to an object being passed as a parameter using ES6 syntax
function personAge(age, { firstName = 'Richard', lastName = 'Hendricks' } = {}) {
console.log(firstName + ' ' + lastName + ' is ' + age + ' years old');
}
personAge(20);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment