Skip to content

truthy values issue explained #989

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions 03_Day_Booleans_operators_date/03_booleans_operators_date.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,17 @@ We agreed that boolean values are either true or false.
- All strings are truthy except an empty string ('')
- The boolean true

#### ⚠️ Note:
Even though non-zero numbers and decimal numbers(like -1,1.5,etc) are truthy in a Boolean context, they are not equal to true when using ==.

Example: Truthy but not equal to true

if (-1) → Evaluates to true because -1 is truthy.

-1 == true → Returns false because true is coerced to 1, and -1 is not equal to 1.

To explicitly check the truthiness of a value, use Boolean(value) or use them in if-else , while or do-while conditional statements.

### Falsy values

- 0
Expand Down