In almost a few examples, I came across the following example:
var foo = {unique_prop: 1};
var bar = {unique_prop: 2};
var object = {};
object[foo] = 'value';
alert(object[bar]);
where two objects foo and bar are created. I do not get a warning (object [bar]); is the "value". What is the connection here between foo and bar.
In addition, a small change will give the result as "undefined" as an example below.
var foo = {unique_prop: 1};
var bar = {unique_prop: 2};
var object = {};
object["foo"] = 'value';
alert(object[bar]);
By default, the notation []can be used on the right line, arent ["some_property"], and [some_property]the same thing?
source
share