JavaScript · The language round

What is the difference between null and undefined?

EasynullundefinedtypesUpdated Oct 2026
Quiz this track

Short answer

undefined usually means a value has not been assigned. null is an intentional empty value. They are loosely equal but strictly different, and both are falsy.

The distinction is about intent. undefined is the default for an uninitialised variable, a missing property, a missing argument or a function with no return value. null is something you assign when you deliberately want to represent no value.

js
let notAssigned;
const empty = null;

console.log(notAssigned); // undefined
console.log(empty); // null
console.log(notAssigned == empty); // true
console.log(notAssigned === empty); // false
console.log(typeof notAssigned); // "undefined"
console.log(typeof empty); // "object"

Where undefined comes from

  • A declared variable with no initial value
  • A missing object property or array element
  • A function parameter that was not supplied
  • A function that returns nothing
  • The value of void

Default parameters only apply when the argument is undefined, not when it is null. That difference matters in API code.

js
function greet(name = "guest") {
  return "Hello, " + name;
}

greet(undefined); // "Hello, guest"
greet(null); // "Hello, null"
typeof null returns "object" because of a historical bug in the first JavaScript engine. Use value === null to check for null.

Follow-ups you should expect

Interviewers use these to check whether the first answer was understanding or memorisation.

  1. 1Why does `typeof null` return `"object"`?
  2. 2Does a default parameter apply when `null` is passed?
  3. 3When should you use `null` instead of `undefined`?
  4. 4What does `value == null` check?

Say it in the interview

undefined usually means a value was never assigned, while null is an intentional empty value. They are loosely equal, so value == null matches both, but they are strictly different. undefined appears for missing properties, missing arguments, and functions without a return. Default parameters only replace undefined, not null. And typeof null is object because of a historical bug, so I check null with strict equality.

Use this as a model, not a script. Saying it in your own words is what makes it survive follow-up pressure.

Related questions

Reading is step one

Now say it out loud.

Understanding an answer and delivering it under pressure are different skills. Rehearse this topic in a live JavaScript mock interview and get scored feedback on depth, clarity and confidence.