Skip to content

Commit 342ab73

Browse files
fix: truthy&falsy.js file
1 parent 56d78aa commit 342ab73

File tree

2 files changed

+33
-34
lines changed

2 files changed

+33
-34
lines changed

part1 (Basics)/03_var_let&const.js

Lines changed: 0 additions & 32 deletions
This file was deleted.

part1 (Basics)/06_truthy&falsy.js

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,41 @@
1-
// INFO: Truthry and Falsy Values
1+
// truthy-falsy.js
2+
3+
// INFO: What are Truthy and Falsy Values?
4+
5+
/*
6+
In JavaScript, every value is either "truthy" or "falsy" when evaluated in a Boolean context (like inside an if condition).
7+
8+
- **Falsy values** are those that are considered false when converted to a Boolean.
9+
- **Truthy values** are all other values that are considered true.
10+
11+
Knowing which values are falsy helps avoid bugs and write cleaner conditions.
12+
13+
---
14+
15+
JavaScript's falsy values are exactly these:
16+
17+
1. false
18+
2. 0
19+
3. -0
20+
4. ""
21+
5. null
22+
6. undefined
23+
7. NaN
24+
25+
Everything else is truthy.
26+
*/
227

328
// NOTE: Falsy Values in JavaScript
429
if (!false) console.log("false is falsy");
530
if (!0) console.log("0 is falsy");
6-
if (!-0) console.log("-0 is falsy value");
31+
if (!-0) console.log("-0 is falsy");
732
if (!"") console.log("empty string is falsy");
833
if (!null) console.log("null is falsy");
934
if (!undefined) console.log("undefined is falsy");
1035
if (!NaN) console.log("NaN is falsy");
36+
37+
// Example of truthy values:
38+
if ("hello") console.log('"hello" is truthy');
39+
if (42) console.log("42 is truthy");
40+
if ([]) console.log("An empty array [] is truthy");
41+
if ({}) console.log("An empty object {} is truthy");

0 commit comments

Comments
 (0)