Question #31

Author: admin
tags: JavaScript  
const z = {};
const a = { a: 1 };
const b = { b: 2 };

z[a] = 3;
z[b] = 4;

console.log(z[a]);
What will the console output be?
1
2
3
4
There will be an error
Objects in JavaScript can only have a String type or a Symbol type as a property name.
In this task, all properties inside square brackets are automatically converted to the String type.
The strings z[a] = 3; and z[b] = 4; added a property named object Object to the object, because the method Object.prototype.toString() was automatically called on these objects, when converting to string.
Rate the difficulty of the question:
easyhard