LESSON 07 / 16·2 min readFoundation

What are null, undefined and NaN?

Try code in the playground
01 Understand02 Recall03 Prepare

Understand the concept

undefined usually means a value has not been supplied, while null is commonly used to mark an intentionally empty value. NaN means a numeric calculation or conversion did not produce a valid number. These are different cases, so an API should not treat them as interchangeable without a clear rule.

Important ideas

  • null: intentionally empty. undefined: missing or not assigned.

  • NaN: a number value representing an invalid numeric result.

  • Use Number.isNaN(value) to check for NaN.

  • A missing object property evaluates to undefined; a JSON response can explicitly contain null.

  • typeof NaN is "number"; the name describes a special number value, not a separate JavaScript type.

PAUSE & RECALL

Can you explain it without the notes?

What are null, undefined and NaN?

Use your own words. Explain an example and one limitation before checking the explanation.

Check your explanation

undefined usually means a value has not been supplied, while null is commonly used to mark an intentionally empty value. NaN means a numeric calculation or conversion did not produce a valid number. These are different cases, so an API should not treat them as interchangeable without a clear rule.

CONNECT IT TO YOUR INTERVIEW

Turn this concept into a clear answer.

  • Use value ?? fallback when only null and undefined should trigger a default; || also replaces valid values such as 0 and an empty string.
Practice this concept
YOUR NEXT STEP

Keep connecting the ideas.

Next lesson: Closures

Adapted from 01_JAVASCRIPT_TYPESCRIPT.md · “What are null, undefined and NaN?”. Examples are study fragments; framework behavior can depend on your version.