I was trying some things today and came across a behaviour I would like to understand.
var b = ({a = 1, b = 1, c = 1}) => a + b + c;
b(); // throws error.
But if it is defined like this
var b = ({a = 1, b = 1, c = 1} = 0) => a + b + c;
b() // returns 3
b([]) // returns 3
Shouldn’t this be an error? Did zero somehow become an object here? Is it somehow equivalent to the following?
var b = ({a = 1, b = 1, c = 1} = {}) => a + b + c; // this is possible I guess.
My question is not how regular destrcuturing and default params work, but only how this particular scenario is being evaluated.
Can some one explain this to me?