Skip to content

Instantly share code, notes, and snippets.

@rahulmalhotra
Created September 6, 2020 10:03
Show Gist options
  • Save rahulmalhotra/2a5fdc8d375c5af46e1b953cb18d77bf to your computer and use it in GitHub Desktop.
Save rahulmalhotra/2a5fdc8d375c5af46e1b953cb18d77bf to your computer and use it in GitHub Desktop.
This code snippet is used in ES6 Spread Operator JavaScript Tutorial by SFDC Stop
// * Spread Operator in JavaScript ES6
function eats(fruit1, fruit2, fruit3) {
console.log('Baby eats :- ', fruit1 + ', ' + fruit2 + ' and ' + fruit3);
}
let fruits = ['apple', 'mango', 'banana'];
// eats(fruits[0], fruits[1], fruits[2]);
eats(...fruits);
// * Rest Parameters
function car(name, ...features) {
console.log('Features of Car ' + name + ' are:- ');
features.forEach(feature => {
console.log(feature);
});
}
car('Audi', 'Great Speed', 'Good Color', 'Comfort', 'Good Looks');
let features = ['Great Speed', 'Good Color', 'Comfort', 'Good Looks'];
let moreFeatures = ['Great Mileage', 'Amazing Design', ...features];
// features.push(...moreFeatures);
console.log(moreFeatures);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment