I have the following code.
a=7
global[{a}]=7
global[{a}] // returns 7
b[{a}]=7
b[{a}] // returns undefined
I honestly have no idea whats going on, it seems like an object with an object as a property, but then i dont see why the second example is undefined.
So here is what I guess is happening.
As you mentioned earlier, global is same as window
object.
So, when you are doing,
global[{a}] = 7;
It's similar to global["[object Object]"] = 7
Then you will get the answer :: global[{}]
as 7
.
Now , for this
b[{a}]=7
b[{a}] // returns undefined
You haven't declared b
as object that's why you are getting answer as undefined.
If you do the following, result would be same;
b = {};
b[{a}]=7;
b[{a}] // returns 7
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With