Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where in the ECMAScript specification can I find the reason about why {} !== {}?

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

  1. 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?

like image 539
Joji Avatar asked Oct 15 '25 16:10

Joji


1 Answers

{} 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.

like image 143
Kaiido Avatar answered Oct 17 '25 05:10

Kaiido