Skip to content

Instantly share code, notes, and snippets.

@rahulmalhotra
Created September 6, 2020 09:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rahulmalhotra/2d5705c605236d599cf9ec21072ad111 to your computer and use it in GitHub Desktop.
Save rahulmalhotra/2d5705c605236d599cf9ec21072ad111 to your computer and use it in GitHub Desktop.
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