1

I found this in JS articles, but i can't find explanation, can someone point to wright direction or explain here?

typeof null; // object
null === Object; // false
4
  • All in javascript is an object, but you can't compare a null value with an object reference. Comparison should be typeof null === "object" Commented Mar 15, 2016 at 9:32
  • typeof null === Object still false Commented Mar 15, 2016 at 9:34
  • RTFM Commented Mar 15, 2016 at 9:35
  • You have to read up some very very basic concepts. like: what is a constructor? What is a value, what is a reference? Comparison: equality vs. identity, ... Commented Mar 15, 2016 at 9:48

2 Answers 2

1

MDN explain it thus:

The value null is a JavaScript literal representing null or an "empty" value, i.e. no object value is present. It is one of JavaScript's primitive values.

The value null is a literal

Further down that page you'll find this:

typeof null        // object (bug in ECMAScript, should be null)
typeof undefined   // undefined
null === undefined // false
null  == undefined // true

Here is a codepen with that very code, showing the results (and the bug talked about)

document.getElementById('test1').innerHTML = typeof null;
document.getElementById('test2').innerHTML = typeof undefined;
document.getElementById('test3').innerHTML = null === undefined;
document.getElementById('test4').innerHTML = null == undefined;
<div id="test1"></div>
<div id="test2"></div>
<div id="test3"></div>
<div id="test4"></div>

Sign up to request clarification or add additional context in comments.

Comments

0

It is because Object is a function. Therefore null is just null and Object is a function.

typeof null === 'object'
typeof Object === 'function'

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.