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
discountCodeset explicitly toundefined - Create
lastPurchaseDateset explicitly tonull - Optionally log both variables so you can see their values in the console
- Export both variables
Required exports
discountCodelastPurchaseDate
Completion criteria
discountCodeisundefinedlastPurchaseDateisnull
π MDN - null
π MDN - undefined