0

Can someone help me understand how could the following statements true in javascript:

  • null == null true
  • null === null true

when typeof null is object and since objects are reference type and no two object can have same address space and can't be equal in both the cases then how it could be true

6
  • 1
    that's because null is a primitive value, not an object Commented Apr 22, 2024 at 17:42
  • 1
    Here is the specification: tc39.es/ecma262/multipage/overview.html#sec-null-value "4.4.15 null value primitive value that represents the intentional absence of any object value" Commented Apr 22, 2024 at 17:42
  • 1
    Here is the reason why typeof null === "object": developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/… It's rather a bug. Commented Apr 22, 2024 at 17:46
  • 2
    null isn't really an object. It's a historical accident that typeof null == 'object' Commented Apr 22, 2024 at 17:47
  • 2
    "no two object can have same address space and can't be equal in both the cases then how it could be true" - even if null was an actual object, why do you assume that null === null does not compare that singleton null object with itself? Commented Apr 22, 2024 at 20:22

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.