[a, b] = [1, 2]
[a, b, ...rest] = [1, 2, 3, 4, 5]
{ a, b } = { a: 1, b: 2 }
{ a, b, ...rest } = { a: 1, b: 2, c: 3, d: 4 } // ES2016
const foo = ['one', 'two', 'three']
const [one, two, three] = foo
// one = 'one', two = 'two', three = 'three'
let a, b
[a, b] = [1, 2]
// a = 1, b = 2
function f() {
return [1, 2, 3]
}
const [a, , b] = f()
// a = 1, b = 3
const o = { p: 42, q: true }
const { p, q } = o;
// p = 42, q = true
const { p: foo, q: bar } = o
// foo = 42, bar = true
function drawChart({ size: size = 'big', cords: cords = { x: 0, y: 0 }, radius: radius = 25 } = {}) {
console.log(size, cords, radius)
}
drawChart({
cords: { x: 18, y: 30 },
radius: 30
})