LESSON 08 OF 50

Observe null and undefined

Compare the historical typeof results for null and undefined.

Official sourceECMAScript — undefined and null valuesReviewed: 2026-08-26
STEP 1 · LEARN

How it works

undefined is used when a binding has no assigned value yet. null is an intentional primitive value; however, for historical reasons, typeof null returns “object”.

Correct example
const emptyValue = null;
let pending;
console.log(typeof emptyValue);
console.log(typeof pending);

The two lines show the real behaviour: object for null and undefined for the uninitialized binding.

Common mistake
const emptyValue = 'null';
let pending = 'undefined';

The texts “null” and “undefined” are strings, not the corresponding primitive values.

STEP 2 · APPLY

Your exercise

Declare emptyValue as null and pending without a value; print typeof for both in that order.

STEP 3 · RUN

Write and run the code

script.jsJAVASCRIPT
Isolated consoleisolated
Preparing the runtime…
Run the code to see the result.
The draft stays only in this browser.Isolated QuickJS · no DOM, session or network
STEP 4 · CHECK

What needs to pass

0%not checked
  • emptyValue is declared with const and null.
  • The source applies typeof to both variables.
  • The output is object, then undefined.
Explain the solution logic

The declarations create distinct values, and typeof reveals both the difference and the historical null exception.