The purpose of this page is to examine how various items are treated when used as booleans.
When testing logical operations and methods on some of the values below, the results are not always obvious. (Itested the code below with Safari on Mac OS X. However, you can use whatever browser you like.)
[]
is the shortcut notion for an empty array. If you state
that var a = [];
the following expressions are true: Boolean(a)
,
a == false
, and a != true
. The same
results occur when the value is
created as var a = new Array();
var a = {}'
or var a = new Object();
, the
expressions that are true are Boolean(a)
, a != false
,
and a != true
.var a = " ";
, the following
expressions are true: Boolean(a)
, a == false
,
and a != true
.