⭐destructuring assignment
// destructuring assignment
let {a} = {a: 1, b: 2};
let [a, b=0, , ...rest] = iterable;// ⭐ array destructuring
let [
a,
b = 0, // default value
, // ignore element
...rest // rest elements as an "array"
] = array
// ⭐ object destructuring
let {
a,
b = 0, // default value
c: newPropName, // new variable name
...rest // rest properties as an "object"
} = object
// ⭐ smart function parameters
function f(a, b, {
c,
d: newPropName = 0, // new parameter name (with default value)
...rest
} = {}){
// do something with: a, b, c, newPropName, rest
}Last updated