In JavaScript We all know that {} !== {} - they are different objects allocated on heap. But I was trying to find the reason at the language specification level.
at https://tc39.es/ecma262/#sec-samevaluenonnumeric it says
- If x and y are the same Object value, return true. Otherwise, return false.
But it is unclear to me how the spec defines exactly when two objects are considered to have the same Object value. Like {} and {} clearly do not have the same value but how exactly is it defined in the spec?
{} in this context is an ObjectLiteral, when the runtime evaluation encounters such an ObjectLiteral it calls OrdinaryObjectCreate which itself calls MakeBasicObject which does return a new object.
So two ObjectLiterals can't be SameObject.
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