Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / JavaScript

The Null type and the null value

Null is a JavaScript primitive type with exactly one value: null. It represents the intentional absence of an object value. Check for it with === null: typeof null returns "object", even though null is not an object.

Version: ECMAScript and Web APIs; exact feature edition and browser support reviewed per entry; Node 24 in repository does not prove browser API support

Syntax

null
value === null

Null is the type name in the ECMAScript specification, while null is the literal for its sole value. It is a primitive value, not an object. You can assign null to explicitly represent the absence of an object value, such as no selected user.

null and undefined belong to different types. The declaration let pendingUser; initializes the variable to undefined, whereas const selectedUser = null; explicitly assigns null. Choose consistent meanings for these states in your application.

To test for this exact value, use value === null. The expression typeof null returns the string "object", but this does not make null an object. Consequently, typeof value === "object" alone does not exclude null.

Strict equality distinguishes these values: null === undefined produces false. Loose equality treats this pair as equal: null == undefined produces true. The example demonstrates both rules; its use of == is intentional to illustrate the difference.

Examples

const selectedUser = null;
let pendingUser;

console.log(selectedUser === null);
console.log(typeof selectedUser);
console.log(selectedUser === pendingUser);
console.log(selectedUser == pendingUser);

Result

true
object
false
true

The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.

Sources