i was taking lessons on ES6 key features but this snippet is troubling my common sense, how does javascript resolve ",b" to be the 2nd item in the return array of the foo function does b in the case implicitly mean 2nd item and z would mean 26th item ?? See code snippet below ...
function foo() {
return [1,2,3];
}
function bar() {
return {
x: 4,
y: 5,
z: 6
};
}
var [,b] = foo();
var { x, z } = bar();
console.log( b, x, z );
// 2 4 6
The lettering does not matter. What matters is the comma.
var [b] would destructure the first element from the array returned by foo().
var [,b] destructures the second element from the array
var [, , b] would destructure the third element.