From: Introduction to ES6 Standards (3rd Edition)

Destruct assignment of function parameters can also be used

    function move ({x = 0, y = 0} = {}) {
        return [x, y]
    }
    
    move({x: 3, y: 8});  // [3, 8]
    move({x: 3});        // [3, 0]
    move({})             // [0, 0]
    move()               // [0, 0]
Copy the code

In the above code, the function move takes an object, which is destructively assigned to get the values of the variables x and y. If deconstruction fails, x and y are equal to the default values.

Note that the following will give you different results.

    function move({x, y} = {x: 0, y: 0}) {
        return [x, y]
    }
    move({x: 3, y: 8});  // [3, 8]
    move({x: 3});        // [3, undefined]
    move({})             // [undefined, undefined]
    move()               // [0, 0]
Copy the code

The above code specifies default values for the arguments to the move function, not for the variables x and y, so you get a different result. Undefined triggers the default value of the function.

[1, undefined, 3].map({x = 'yes'} => x) // [1, 'yes', 3]
Copy the code