Skip to content

null

In JavaScript, null is a primitive type whose only value, null, represents the intentional absence of an object value. It’s one of JavaScript’s primitive types, even though the typeof operator reports it as 'object':

Language: JavaScript
> null
null

> typeof null
'object'

> null === null
true

Like every primitive, null is immutable and compares by value, so === and Object.is() both treat any two null values as the same.

null Literal and typeof

The null value is written with the null literal, which is also a reserved word, so it can’t name a variable or a function. Code usually assigns null on purpose, for example to clear a reference or to signal that a lookup found nothing:

Language: JavaScript
> let selected = { id: 7 };
undefined

> selected = null;
null

> "abc".match(/x/)
null

The 'object' result of typeof null is a historical quirk from the first JavaScript engine, and the specification keeps it for compatibility. A reliable null check compares with === instead:

Language: JavaScript
> const value = null;
undefined

> typeof value === "object"
true

> value === null
true

null vs. undefined

Both values mean “nothing here”, but undefined is what JavaScript produces for a missing value, while null is what code assigns on purpose. Loose equality treats them as equal to each other, and strict equality tells them apart:

Language: JavaScript
> null == undefined
true

> null === undefined
false

> Number(null)
0

> Number(undefined)
NaN

Common null Gotchas

Reading a property of null throws a TypeError, just like reading one of undefined. Optional chaining with ?. returns undefined instead of throwing:

Language: JavaScript
> const account = null;
undefined

> account.name
Uncaught TypeError: Cannot read properties of null (reading 'name')

> account?.name
undefined

Default parameter values don’t apply to null, only to undefined, so passing null skips the default:

Language: JavaScript
> function greet(name = "guest") { return `Hello, ${name}!`; }
undefined

> greet(null)
'Hello, null!'

Have a question about this? Mentor AI can show you examples, compare related terms, and point you to tutorials.


By Leodanis Pozo Ramos • Updated Nov. 4, 2026