Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

JS Puzzles · Const

typeof null

typeof null returns "object", even though null is a separate JavaScript type and is not an object. This historical behavior is retained for compatibility.

How it works

null is a standalone value representing nothing, emptiness, or an unknown value. Although it has its own type, typeof null produces the string "object" because of a historical language error preserved for compatibility, so strict equality is required for an exact null check.

Syntax

typeof x

Parameters

NameTypeDescription
xany JavaScript expressionThe value or expression whose type name should be returned.

Returns

A string containing the operand's type name; for null, the result is "object".

Key points

  • null is not grouped with the other values described in the lesson; it forms its own distinct type.
  • The null type has exactly one value: null.
  • Assign null when a value intentionally means nothing, is empty, or is not yet known.
  • typeof does not return a type object; it returns a string naming the operand's type.
  • The operator accepts either the usual unparenthesized form or a parenthesized expression.
  • The special case is exact: evaluating typeof null yields the string "object".

Common mistakes

  • typeof null is an officially recognized error, so the returned string does not mean that null is an object.
  • Do not infer object-ness from typeof null; null remains a separate special value.
  • Use value === null when the code must distinguish null from actual objects.

Example: Testing null correctly

const value = null;

console.log(typeof value); // "object"
console.log(value === null); // true

Use strict equality to test for null; typeof alone reports the misleading string "object".

When to use it

Inspecting a value's type

A variable may hold different kinds of values and code needs a quick type-name check.

Checking for null explicitly

A program must distinguish an absent value from an actual object.

Teaching the null quirk

An explanation or debugging output needs to demonstrate JavaScript's historical typeof behavior.

Interview questions

QWhat does typeof null return, and is null an object?

typeof null returns the string "object". This is a historical typeof error that JavaScript keeps for compatibility, even though null has a separate type.

Follow-up: How should null be detected? Use strict equality: value === null.

QWhat does null represent in JavaScript?

null is a special standalone value representing nothing, emptiness, or an unknown value. It is not a reference to a nonexistent object or a null pointer.

Follow-up: What does typeof report for null? It reports "object" because of the longstanding language error.

QHow is the typeof operator written, and what does it return?

The normal form is typeof x, and typeof(x) is also valid because the parentheses are optional. The result is a string naming the operand's type.

Follow-up: What special result must be remembered? typeof null is "object", despite null not being an object.

  • typeof
  • null
  • undefined
  • object

Source: Data types. Checked 2026-10-15.