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:
false0,-0,0n''(empty string)nullundefinedNaN
You can convert any value to a boolean with
Boolean(value) or !!value.π¨ Open
. The starter provides these fixtures:
| Name | Value |
|---|---|
username | 'kent' |
nickname | '' (empty string) |
age | 0 |
email | 'kent@epicweb.dev' |
password | '' (empty string) |
notes | undefined |
cartTotal | 42 |
hasAcceptedTerms | false |
Create and export:
hasUsernameβ boolean for whetherusernameis truthyhasNicknameβ boolean for whethernicknameis truthyhasAgeβ boolean for whetherageis truthyhasNotesβ boolean for whethernotesis truthycanCheckoutβtrueonly whencartTotalis truthy andhasAcceptedTermsistruecanCreateAccountβtrueonly whenhasUsername,email, andpasswordare all truthy
Required exports
hasUsername, hasNickname, hasAge, hasNotes, canCheckout,
canCreateAccountCompletion criteria
Each export must be a real boolean (
typeof "boolean"). Use the fixtures and
the falsy list above to reason about (or log) what each expression evaluates
toβdon't hardcode the answers.π° Convert values to booleans when you need a strict true/false.
π MDN - Truthy
π MDN - Falsy


