tgoop.com/web_dev_bds/327
Last Update:
The output will be 456
Here's how:
- a is initialized as an empty object using {}.
- b is initialized as an object with a property key set to the string 'b'.
- c is initialized as an object with a property key set to the string 'c'
The code assigns values to properties of a using b and c as keys. But, when a non-string value is used as a property key, it is automatically converted to a string.
Then:
- a[b] = 123 assigns 123 to the property with key 'object Object' in a.
- a[c] = 456 assigns 456 to the property with key 'object Object' in a. This overwrites the previous value.
Finally, console.log(a[b]) is called, that accesses the value of the property with key 'object Object' in the a object and it returns 456 since the value was overwritten with 456
BY Web development

Share with your friend now:
tgoop.com/web_dev_bds/327