This is the syntax of ES2015. A function declaration combines Destination Assignment with a default value.
This is the basic purpose of destructuring using an object:
var {a, b} = {a: "foo", b: "bar"}; console.log(a);
You can add default values ββto the left side:
var {a = "foo", b = "bar"} = {}; console.log(a);
When you specify arguments when declaring a function, you do not use var
, and when you destroy the object, it will be the same:
function test({a = "foo", b = "bar"}){ console.log(a + b); } test({});
And of course, you can define a default value so that your function does not accept any arguments.
function test({a = "foo", b = "bar"} = {}){ console.log(a + b); } test();
source share