Introduction

In JavaScript, boolean (true or false) types and comparisons are not the only forms of truthy and falsy values. But first, what are truthy and falsy values?

As the names suggest...

Bit by Bot Here are the falsy values:

Falsy Value Description
false
If the boolean variable is set to be false, then it will evaluate to false.
0
If the value of the number is 0, then it will be considered as falsy.
"" or ''
If the string is blank (empty), then it will evaluate to false.
null
If there is no value at all, then JavaScript will return a value called null, which will also be considered as falsy.
undefined
If a variable is declared but not assigned a value, then it will return a value called undefined and will also evaluate to false.
NaN
If the value is not a number, (e.g. divide a string by a number), then NaN (Not a Number) will be returned and will evaluate to false.

** NOTE: Values other than the ones listed above are truthy values! **

Test it Out!

Go through each example below to see whether or not they will evaluate to false!

Bit by Bot Using a Computer

false:

let friday
=
false
;
if
(!friday) {

alert("Today is not Friday!");

}


0:

let grade
=
0
;
if
(!grade) {

alert("This is not a valid grade!");

}


Empty String:

let sentence
=
""
;
if
(!sentence) {

alert("This is a blank string!");

}


null Value:

let rank
=
null
;
if
(!rank) {

alert("Your rank is currently unavailable!");

}


undefined Value (unassigned value):

let word
;
if
(!word) {

alert("This variable has not been assigned a value yet!");

}


NaN Value (invalid number):

let food
=
"jelly" / 3
;
if
(!food) {

alert("There is a problem with the number!");

}