-1

Why null is an object in JavaScript, but null instanceof Object returns false? Is it because of the different constructors?

Ivar
  • 6,138
  • 12
  • 49
  • 61
  • Do you have an example you would like us to take a look at in context? – ed2 Aug 27 '20 at 11:52
  • 3
    Who said that? null is a primitive value in Javascript. – jperl Aug 27 '20 at 11:52
  • 5
    Does this answer your question? [Javascript confusing syntax inconsistence for null, instanceof and typeof?](https://stackoverflow.com/questions/28956060/javascript-confusing-syntax-inconsistence-for-null-instanceof-and-typeof) – Sudhir Ojha Aug 27 '20 at 11:52
  • The answer to "why" is always "because that's how the specification is written". – Heretic Monkey Aug 27 '20 at 11:53
  • Related: [Why is typeof null “object”?](https://stackoverflow.com/questions/18808226/why-is-typeof-null-object) – Ivar Aug 27 '20 at 12:00

1 Answers1

0

null is not an object in JavaScript, it is a primitive type. There is a known that typeof null === 'object' but still, null counts as a primitive and instanceof returns false for all primitives.

Boussadjra Brahim
  • 82,684
  • 19
  • 144
  • 164
Anton
  • 440
  • 3
  • 10