Created
May 20, 2018 10:57
-
-
Save valerymelou/1829e21bc03e7a6809b3530c7a9562dc to your computer and use it in GitHub Desktop.
This file contains hidden or 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
// Example 1 | |
const order = [20.17, 18.67, 1.50, "cheese", "eggs", "milk", "bread"]; | |
const [total, subtotal, tax, ...items] = order; | |
console.log(total, subtotal, tax, items); // 20.17 18.67 1.5 ["cheese", "eggs", "milk", "bread"] | |
// Example 2 | |
function sum(...nums) { | |
let total = 0; | |
for(const num of nums) { | |
total += num; | |
} | |
return total; | |
} | |
console.log(sum(10, 20, 30)); // 60 | |
console.log(sum(20, 20)); // 40 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment