0

I'm new to JavaScript so have a question on objects and their reference. Let's say we have empty objects

{}=={}

if you write this line in console, it returns false

{}==={}

it returns false on above line of code too.

but let say we have

a=2
b=a
b==a
b===a

it returns true in this case.

can anyone please explain what's happening on back side in both cases?

BadPiggie
  • 5,471
  • 1
  • 14
  • 28
TimeToCode
  • 1,458
  • 3
  • 18
  • 60
  • The details are in [the standard](https://tc39.es/ecma262/multipage/ecmascript-language-expressions.html#sec-equality-operators). – Teemu Jan 20 '22 at 06:18
  • short reasoning: 1) an assignment *never* creates a new object (primitives are immutable and have special conversion rules in equality, so wether or not they are copied is irrelevant); 2) `{}` (as expression) always creates a new object. (And mixing in a primitive type/value (`2`) does not help the question at all when comparing the behavior of the equality between Object values.) – user2864740 Jan 20 '22 at 06:23

0 Answers0