null

A special value meaning no value or no object, set on purpose to show that something is empty or absent.

In more detail

Using null as if it were a real object, such as calling a method on it, crashes the program or throws an error, so code must check for it first. Many type systems let you mark whether a value may be null, as string | null does in TypeScript, which makes absence explicit. In JavaScript, null is distinct from undefined, and typeof null returns "object", a long-standing quirk.

Examples

In the browser: Code must check for null before using a result, or it will throw an error when it reads a property. The optional chaining operator ?. in the examples does that check for you.
Java: calling a method on null throws NullPointerException; the course uses Optional for lookups that may find nothing.

Related terms

Taught in

References