File tree Expand file tree Collapse file tree 2 files changed +33
-34
lines changed
Expand file tree Collapse file tree 2 files changed +33
-34
lines changed Load Diff This file was deleted.
Original file line number Diff line number Diff line change 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
429if ( ! false ) console . log ( "false is falsy" ) ;
530if ( ! 0 ) console . log ( "0 is falsy" ) ;
6- if ( ! - 0 ) console . log ( "-0 is falsy value " ) ;
31+ if ( ! - 0 ) console . log ( "-0 is falsy" ) ;
732if ( ! "" ) console . log ( "empty string is falsy" ) ;
833if ( ! null ) console . log ( "null is falsy" ) ;
934if ( ! undefined ) console . log ( "undefined is falsy" ) ;
1035if ( ! 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" ) ;
You can’t perform that action at this time.
0 commit comments