I have the following pieces of code (which only parses and runs correctly in Firefox)
var {A: a} = {A: 1};
console.log(a); // 1
And now we have a variable called 'a' with value is 1
So I have 3 questions to ask
- Why do we need 'var' here? Why don't we need var on the rhs of '='
- How does 'a' be in the scope ?
- How does 'a' get assigned to 1?
it seems uses member-wise copy here, but why?
shouldn't the object on the lhs will reference to the object on rhs?
For example,
var b = {B: 1};
var c = {B: 2};
b = c;
b.B = 3;
console.log(c);
In this assignment(b = c), b now references to c, and they share the same object. Why this assignment differs from my original one?
Forgot to mention I am testing on Firefox 16.0