Null and Undefined

Null and Undefined
πŸ‘¨β€πŸ’Ό Not every product has all fields filled in. We need to handle missing data gracefully. This is where null and undefined come in.
The difference:
  • undefined - The value hasn't been set (default for uninitialized variables)
  • null - The value was intentionally set to "nothing"
let middleName = undefined // not set yet
const deletedAt = null // intentionally empty
🐨 Open
index.ts
and:
  1. Create a variable discountCode set to undefined
  2. Create a variable lastPurchaseDate set to null
  3. Log both variables to see their values
πŸ“œ MDN - null

Please set the playground first

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