ForgeFrontend — Prepare, Practice, Crack
Secure checkout
Lifetime access
Instant Drive delivery
Free updates forever

Prepare · Practice · Crack

What is the difference between null and undefined?

Quick answer

`undefined` means a variable was declared but never assigned; `null` is an intentional 'no value' you assign yourself.

In detail

The engine gives `undefined` to uninitialised variables, missing params, and absent object properties. `null` is set explicitly to signal emptiness. They are loosely equal (`null == undefined`) but not strictly (`null === undefined` is false), and `typeof null` is the historic bug "object" while `typeof undefined` is "undefined".

1let x;            // undefined
2const y = null;   // intentional empty
3null == undefined;   // true
4null === undefined;  // false
5typeof null;         // "object" (bug)
6typeof undefined;    // "undefined"

Why interviewers ask this: Tests precision about JavaScript's two 'empty' values.

This is 1 of 118+ questions in the JavaScript Interview Kit

Get every question with detailed answers, follow-ups and real code — plus coding challenges and a last-minute revision sheet. One-time payment, instant access.

⚡ Get the JavaScript Interview Kit → ₹299

Full kit

JavaScript Interview Kit · ₹299

Get it →