Video Lesson

Lesson Notes


null vs undefined

In JavaScript, undefined means a variable has been declared but not given a value, whereas null is an assignment value that represents “no value.”

1// undefined example 2let x; 3console.log(x); // undefined 4 5// null example 6let y = null; 7console.log(y); // null

When to use:

  • Use undefined to signify an uninitialized variable or missing function arguments.
  • Use null to explicitly indicate that a variable should have no value.

Key Points:

  • typeof undefined returns "undefined".
  • typeof null returns "object" (a known JavaScript quirk).
  • Both null == undefined is true, but null === undefined is false.

AI Assistant

Sign In Required

Sign in and subscribe to use the AI assistant for instant help with your lessons.

Sign In

Javascript "null" vs "undefined"

In JavaScript, undefined means a variable has been declared but not given a value, whereas null is an assignment value that represents “no value.”

3m 20s

Course Content

0 of 32 lessons completed
6. Promises, Async and Await
0 of 0 completed
7. The DOM
0 of 0 completed