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. null was represented as the NULL pointer (0x00 in most platforms). Consequently, null had 0 as type tag, hence the "object" typeof return value. (reference)

A fix was proposed for ECMAScript (via an opt-in), but was rejected. It would have resulted in typeof null === 'null'.

Answer from Deepak Ingole on Stack Overflow
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Operators › null
null - JavaScript - MDN Web Docs
The null keyword refers to the null primitive value, which represents the intentional absence of any object value. function getVowels(str) { const m = str.match(/[aeiou]/gi); if (m === null) { return 0; } return m.length; } console.log(getVowels("sky")); // Expected output: 0 ... The keyword ...
🌐
web.dev
web.dev › learn › javascript › data-types › null-undefined
null and undefined | web.dev
The strict equality operator considers operands of different data types to be unequal. null == undefined > true null === undefined > false · Unlike the reserved keyword null, undefined is a property of the global object. This was a design decision made early in JavaScript's development, and it let legacy browsers overwrite undefined completely.
Discussions

javascript - Why is typeof null "object"? - Stack Overflow
However, there is actually one logical explanation behind why null is an object in javascript. In the initial version of JavaScript, values were stored in 32 bit units which consisted of a small type tag (1–3 bits) and the actual data of the value. The type tags were stored in the lower bits ... More on stackoverflow.com
🌐 stackoverflow.com
JavaScript: What is the data type of null? - Stack Overflow
It is said that null, in JavaScript, is a primary type. However, when I use the operator typeof on null, it returns "Object". What is the underlying procedure that made typeof to return "Object" i... More on stackoverflow.com
🌐 stackoverflow.com
May 5, 2018
javascript - Why is null an object and what's the difference between null and undefined? - Stack Overflow
Oh right, like in C, where ... programs data). 2016-02-03T19:19:16.96Z+00:00 ... Programmers can also use undefined to indicate "no value", and JS can also use null to indicate "no value". 2016-08-09T23:02:41.423Z+00:00 ... It is not a bug, it is a deliberate choice (see my answer). NaN !== NaN is also not a bug (and also nothing to do with JS). 2020-09-22T15:01:33.523Z+00:00 ... A property when it has no definition is undefined. a null is an object. Its type is ... More on stackoverflow.com
🌐 stackoverflow.com
April 4, 2024
node.js - is null , undefined and false data types in javascript? - Stack Overflow
Are Null, Undefined and false are same in data types in javascript ? if(null){ //This code won't work } if(false){ //This code won't work } if(undefined){ //This code won't work } are... More on stackoverflow.com
🌐 stackoverflow.com
🌐
Programiz
programiz.com › javascript › null-undefined
JavaScript null and undefined
In JavaScript, null is treated as an object. You can check this using the typeof operator. The typeof operator determines the type of variables and values.
🌐
W3Schools
w3schools.com › js › js_typeof.asp
JavaScript typeof
An empty string has both a legal value and a type. ... In JavaScript null is "nothing". It is supposed to be something that doesn't exist. Unfortunately, in JavaScript, the data type of null is an object.
🌐
GeeksforGeeks
geeksforgeeks.org › null-in-javascript
Null in JavaScript | GeeksforGeeks
June 5, 2024 - In JavaScript, both undefined and null represent the absence of a meaningful value, but they have different purposes and are used in distinct contexts. Knowing when and how to use each can help you write clearer, more predictable code.
🌐
Study.com
study.com › computer science courses › introduction to javascript
JavaScript Data Types: Undefined, Null & Boolean - Lesson | Study.com
September 7, 2023 - Although undefined and null are both valid values in JavaScript, for most practical purposes, they denote empty values and carry no information. You can treat them as interchangeable for most of the times when you encounter them.
🌐
YouTube
youtube.com › watch
Javascript null data type explained | JS for Beginners Ep. 14 - YouTube
The null data type in JavaScript is a primitive value that is used to indicate the absence of an object or data. In this beginner tutorial, we look at exampl...
Published   January 21, 2026
Find elsewhere
🌐
JavaScript.info
javascript.info › tutorial › the javascript language › javascript fundamentals
Data types
July 9, 2024 - Normally, one uses null to assign an “empty” or “unknown” value to a variable, while undefined is reserved as a default initial value for unassigned things. The object type is special. All other types are called “primitive” because their values can contain only a single thing (be it a string or a number or whatever). In contrast, objects are used to store collections of data and more complex entities.
🌐
BigBinary Academy
courses.bigbinaryacademy.com › learn-javascript › undefined-and-null › the-null-data-type
The null Data Type - JavaScript | BigBinary Academy
May 5, 2018 - `null` is a data type in JavaScript. It is used to denote the value of **nothing** in a variable. When a variable is `undefined`, it means it has been given no value to hold. Whereas, when a variable is `null`, it means the variable has a value, the value `null`.
🌐
W3Schools
w3schools.com › js › js_datatypes.asp
JavaScript Data Types
In programming, data types is an important concept. To be able to operate on variables, it is important to know something about the type. Without data types, a computer cannot safely solve this: ... Does it make any sense to add "Volvo" to sixteen? Will it produce an error or will it produce a result? ... When adding a number and a string, JavaScript will treat the number as a string.
Top answer
1 of 16
1533
(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.

2 of 16
147

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
🌐
Medium
medium.com › @maciejpoppek › understanding-data-types-in-javascript-null-undefined-and-beyond-f3674995c9f8
Understanding Data Types in JavaScript: null, undefined, and Beyond | by Maciej Poppek | Medium
February 21, 2020 - Type: null is an object, while undefined is a type unto itself. Usage: null is used to indicate an intentional absence of value. undefined indicates that a variable has been declared but not yet assigned a value.
🌐
YouTube
youtube.com › shorts › AFOCcW4v-AA
Null Data Type In Javascript - YouTube
In this video, we'll dive deep into the Null data type in JavaScript. Null is a primitive value that represents the intentional absence of any object value. ...
Published   June 29, 2024
🌐
Syncfusion
syncfusion.com › blogs › javascript › null vs. undefined in javascript
Null vs. Undefined in JavaScript | Syncfusion Blogs
December 10, 2024 - Although both null and undefined are primitive values in JavaScript because of a historical error that transpired, typeof(null) returns “object”. On the other hand, typeof(undefined) is “undefined”.
🌐
JavaScript Tutorial
javascripttutorial.net › home › javascript tutorial › javascript data types
JavaScript Data Types
November 15, 2024 - It’s important to note that the ... language: JavaScript (javascript) The null type is the second primitive data type that also has only one value null....
🌐
Mozilla
developer.mozilla.org › en-US › docs › Web › JavaScript › Guide › Data_structures
JavaScript data types and data structures - JavaScript | MDN
For symbols and BigInts, JavaScript has intentionally disallowed certain implicit type conversions. All types except Object define immutable values represented directly at the lowest level of the language. We refer to values of these types as primitive values. All primitive types, except null, can be tested by the typeof operator.
🌐
Reddit
reddit.com › r/learnjavascript › how do i check if the type of data type is null?
r/learnjavascript on Reddit: how do I check if the type of data type is null?
January 21, 2025 -

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?) } };