How node.js batch assignment

1. array of analytical assignments

let a = 1;
let b = 2;
let c = 3;

Equivalent to

let [a, b, c] = [1, 2, 3];

Defaults

let [a, b = "B"] = ["a", undefined]
console.log(a, b)

When the assignment is undefined, the default value will take effect

2. Object resolve assignment

let { foo, bar } = { foo: 'A', bar: 'B' };
console.log(foo ,bar)
//A B

Defaults

let {x, y = 5} = {x: 1};
console.log(x, y)
//1 5

3. string parsing assignment

const [a, b, c, d, e] = 'hello';

4. analytic function parameters assigned

function add([x, y]){
    return x + y;
}

console.log(add([1, 2])); // 3

Guess you like

Origin www.cnblogs.com/chenqionghe/p/11411544.html