Truthy and Falsy

Truthy Falsy
πŸ‘¨β€πŸ’Ό We often need to decide if a value "exists" without comparing it to null or undefined. JavaScript treats some values as falsy, and everything else as truthy.
Falsy values:
  • false
  • 0, -0, 0n
  • '' (empty string)
  • null
  • undefined
  • NaN
You can convert any value to a boolean with Boolean(value) or !!value.
🐨 Open
index.ts
and:
  1. Create hasUsername based on the truthiness of username
  2. Create hasNickname based on the truthiness of nickname
  3. Create hasAge based on the truthiness of age
  4. Create hasNotes based on the truthiness of notes
  5. Create canCheckout that's true when cartTotal is truthy and hasAcceptedTerms is true
  6. Create canCreateAccount that's true when hasUsername, email, and password are all truthy
πŸ’° Convert values to booleans when you need a strict true/false.
πŸ“œ MDN - Truthy πŸ“œ MDN - Falsy

Please set the playground first

Loading "Truthy and Falsy"
Loading "Truthy and Falsy"
Login to get access to the exclusive discord channel.
Loading Discord Posts