DEV Community

Jingwen Xu
Jingwen Xu

Posted on

An easy way to understand Booleans

Why true why false?
Why 0 is false?

Mainly just think as if it is valuable .

let example1 = false;
let example2 = true;
let example3 = null;
let example4 = undefined;
let example5 = '';
let example6 = NaN;
let example7 = -5;
let example8 = 0;)

like

0 doesn’t value any, so 0 is false,
"" has nothing inside,(no value) that is why is is false.
" " with space, it has something inside, and is a string, has value, so it is true.

NaN not a number, doesn’t value any.
-5 is value of -5. so it is valuable.

At the beginning I was always use false as wrong, but it is mainly just by value, has value? or doesn’t value any.

That's my understanding ...
Hope this can help you as well.

Top comments (0)