Skip to content

Instantly share code, notes, and snippets.

@CodHeK
Last active August 16, 2018 11:24
Show Gist options
  • Save CodHeK/28b056485bedcfbfc94ad5724377ea1b to your computer and use it in GitHub Desktop.
Save CodHeK/28b056485bedcfbfc94ad5724377ea1b to your computer and use it in GitHub Desktop.
desconstruction
let nums = [1, 2, 3]
let [a, b] = nums
console.log(a) //prints 1
console.log(b) //prints 2
let nums = [1, 2, 3]
let [a, ,c] = nums
console.log(a) //prints 1
console.log(c) //prints 3
let a = 1, b = 2;
let [b, a] = [a, b]
console.log(a) //prints 2
console.log(b) //prints 1
//Swaps the values!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment