Created
September 6, 2020 10:03
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// * 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