Created
November 24, 2022 19:23
-
-
Save barneycarroll/b1cda87d88a048a29a7968a675b7d9cd to your computer and use it in GitHub Desktop.
WIP for a little demonstration of the various functions of ... operators in Javascript
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
const object = {a: 1, b: 2} | |
const array = [3,4] | |
// Value expression | |
const foo = {...object, c: 3} // == {a: 1, b: 2, c: 3} | |
const bar = [...array, 5, 6] // == [3, 4, 5, 6] | |
// Destructuring assignment | |
{ | |
const {a, ...rest} = foo // a == {a: 1}; rest == {b: 2, c: 3} | |
} | |
{ | |
const [b, c, ...rest] = bar // b == 3; c == 4; rest == [5, 6] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment