Skip to content

Instantly share code, notes, and snippets.

@barneycarroll
Created November 24, 2022 19:23
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save barneycarroll/b1cda87d88a048a29a7968a675b7d9cd to your computer and use it in GitHub Desktop.
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
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