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