Skip to content Skip to sidebar Skip to footer

Ecmascript 2015, Iterable Destructuring Expression

I am right now experimenting with the iterable destructuring expression, and i am wondering why a specific way does not work. Maybe you can help me on that. For example that works:

Solution 1:

Notwithstanding the === performs a reference equality check, per Benjamin's answer, the reason your first test returns true is because the result of the assignment:

[x, y] = myArray 

is not[x, y], but is instead myArray - the assignment operator evaluates to the RHS, not the newly assigned LHS.

So given:

([x,y] = myArray) === myArray

the LHS of the === evaluates to myArray which is exactly the same object as you have on the RHS, so the result is true.

Solution 2:

=== compares objects by references, since myArray and [x, y] evaluate to a different array.

[] === []; //false
{} === {}; //false

Post a Comment for "Ecmascript 2015, Iterable Destructuring Expression"