Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Default Params
- function sum(x = 10, y = 20) {
- return x + y
- }
- console.log(sum()) // 30
- // Rest Params
- function sum(x, y, ...abc) { // ...abc = [30,40,50]
- let total = abc.reduce((a,b) => a + b) // 30+40+50 = 120
- return x + y + total // 10 + 20 + 120 = 150
- }
- console.log(sum(10, 20, 30, 40, 50)) // 150
- // Spread Operator
- let people = ['foo', 'bar', 'jar']
- let others = ['pippo', 'pluto', ...people]
- let numbers = [1,2,3,4,5]
- console.log(sum(...numbers)) // 15
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement