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
and:
- Create a variable
discountCodeset toundefined - Create a variable
lastPurchaseDateset tonull - Log both variables to see their values
π MDN - null
π MDN - undefined