How to remember falsy values in JavaScript?
Remembering falsy values is like always doubting myself.
I was recently introduced to this book called I don't know Javascript by Kylie Simpson, where I am reading You Don't Know JS: Up & Going, the second chapter Of Javascript and I read about truthy and falsy values.
So what are truthy and falsy values?
Falsy values in javascript are some non-boolean values coerced (converted i guess) to boolean values.
Truthy values are values other than falsy values.
Before listing falsy values I would list the common primitive data types in javascript:
string, number, null, undefined, boolean
*symbols and bigint are skipped for now
So listing falsy values now :
"" : empty string, type of STRING
0 : zero, type of NUMBER
-0 : negative zero, type of NUMBER
NaN: Not a Number, type of NUMBER
null: null primitive data type
undefined: again primitive data type
So out of 7 primitive data types, 3 of NUMBERS (0, -0 and NaN), 1 of STRING ("") and null and undefined are falsy values.
So for remembering purpose we can divide falsy values according to their primitive data types.