Java Reference
In-Depth Information
Booleans
There are only two Boolean values:
true
and
false
. They are named after George Boole,
an English mathematician who worked in the field of algebraic logic. Boolean values are
fundamental in the logical statements that make up a computer program. Every value in
JavaScript has a Boolean value and most of them are
true
(these are known as 'truthy' val-
ues).
To find the Boolean value of something, you can use the
Boolean
function like so:
Boolean(“hello”);
<< true
Boolean(42);
<< true
Boolean(0);
<< false
Only seven values are always
false
and these are known as falsy values:
* "" // double quoted empty string
* '' // single quoted empty string
* 0
* NaN
* false
* null
* undefined
Note: Truthy and Falsy Values
The fact that empty strings and zero are considered falsy can cause confusion
at times, especially since other programming languages don't behave simil-
arly. A ninja needs to be especially careful when dealing with numbers that
might be zero, or strings that are empty.
