Null and Undefined

๐Ÿ‘จโ€๐Ÿ’ผ JavaScript has two special values that represent "nothing" or "no value":
  • undefined - A variable that hasn't been assigned a value yet
  • null - An intentional "empty" or "nothing" value
These might seem similar, but they have different meanings:
  • undefined means "this doesn't have a value yet"
  • null means "this intentionally has no value"
๐Ÿจ Open and explore these special values:
  1. Create a variable notAssigned without giving it a value
  2. Create a variable intentionallyEmpty and set it to null
  3. Log both variables with their types using typeof
  4. Compare them with == and === to see the difference
๐Ÿ’ฐ You can declare a variable without a value:
let myVariable
console.log(myVariable) // undefined
๐Ÿฆ‰ Fun fact: typeof null returns "object" - this is actually a bug in JavaScript from the very first version, but it can't be fixed now because too much code depends on it!
๐Ÿ“œ null on MDN ๐Ÿ“œ undefined on MDN

Please set the playground first

Loading "Null and Undefined"
Loading "Null and Undefined"