From the MDN page about the behaviour of the typeof operator:
Answer from Deepak Ingole on Stack Overflow
null// This stands since the beginning of JavaScript typeof null === 'object';In the first implementation of JavaScript, JavaScript values were represented as a type tag and a value. The type tag for objects was 0.
nullwas represented as the NULL pointer (0x00 in most platforms). Consequently, null had 0 as type tag, hence the "object"typeofreturn value. (reference)A fix was proposed for ECMAScript (via an opt-in), but was rejected. It would have resulted in
typeof null === 'null'.
javascript - Why is typeof null "object"? - Stack Overflow
JavaScript: What is the data type of null? - Stack Overflow
javascript - Why is null an object and what's the difference between null and undefined? - Stack Overflow
node.js - is null , undefined and false data types in javascript? - Stack Overflow
Videos
From the MDN page about the behaviour of the typeof operator:
null// This stands since the beginning of JavaScript typeof null === 'object';In the first implementation of JavaScript, JavaScript values were represented as a type tag and a value. The type tag for objects was 0.
nullwas represented as the NULL pointer (0x00 in most platforms). Consequently, null had 0 as type tag, hence the "object"typeofreturn value. (reference)A fix was proposed for ECMAScript (via an opt-in), but was rejected. It would have resulted in
typeof null === 'null'.
If
nullis a primitive, why doestypeof(null)return"object"?
Because the spec says so.
11.4.3 The
typeofOperatorThe production UnaryExpression :
typeofUnaryExpression is evaluated as follows:
- Let val be the result of evaluating UnaryExpression.
- If Type(val) is Reference, then
a. If IsUnresolvableReference(val) is true, return "undefined".
b. Let val be GetValue(val).- Return a String determined by Type(val) according to Table 20.
(name is undefined)
You: What is name? (*)
JavaScript: name? What's a name? I don't know what you're talking about. You haven't ever mentioned any name before. Are you seeing some other scripting language on the (client-)side?
name = null;
You: What is name?
JavaScript: I don't know.
In short; undefined is where no notion of the thing exists; it has no type, and it's never been referenced before in that scope; null is where the thing is known to exist, but it's not known what the value is.
One thing to remember is that null is not, conceptually, the same as false or "" or such, even if they equate after type casting, i.e.
name = false;
You: What is name?
JavaScript: Boolean false.
name = '';
You: What is name?
JavaScript: Empty string
*: name in this context is meant as a variable which has never been defined. It could be any undefined variable, however, name is a property of just about any HTML form element. It goes way, way back and was instituted well before id. It is useful because ids must be unique but names do not have to be.
The difference can be summarized into this snippet:
alert(typeof(null)); // object
alert(typeof(undefined)); // undefined
alert(null !== undefined) //true
alert(null == undefined) //true
Checking
object == null is different to check if ( !object ).
The latter is equal to ! Boolean(object), because the unary ! operator automatically cast the right operand into a Boolean.
Since Boolean(null) equals false then !false === true.
So if your object is not null, but false or 0 or "", the check will pass because:
alert(Boolean(null)) //false
alert(Boolean(0)) //false
alert(Boolean("")) //false
- Data type of
nullisobject - Data type of
falseisboolean - Data type of
undefinedisundefined
So they are different.
Internally, JavaScript sets a value to one of six primitive data types:
- Undefined (a variable with no defined value)
- Null (a single null value)
- Boolean (true or false)
- Number (this includes Infinity and NaN – not a number!)
- String (textual data)
- Symbol (a unique and immutable primitive new to ES6/2015)
- Everything else is an Object — including arrays.
Here are the complete list of JavaScript falsy values

Is there a variable or function I can use to let the computer know how to differenciate between null and undefined?
This is my previous code trying to do that, but both null and undefined will give me the same output.
if(typeof(jsType) === 'string'){
console.log(`That's just some text.`)}else if(typeof(jsType) === 'number'){ console.log(That's a good number.) } else if(typeof(jsType) === 'boolean'){ console.log(To bool, or not to bool?) } else if(typeof(jsType) === 'undefined'){ console.log(Nothing, but I didn't set that.) } else if(typeof(jsType) === 'null'){ console.log(Nothing, and I did set that.) } else if(typeof(jsType) === 'object'){ console.log(Anybody got the key?) } else if(typeof(jsType)){ console.log(Anybody got the key?) } };
