Mega Code Archive

 
Categories / JavaScript Tutorial / Number Data Type
 

Casting to Boolean value

The Boolean() type cast returns true when the value is a string with at least one character, a number other than 0, or an object; The Boolean() type cast returns false when the value is an empty string, the number 0, undefined, or null. var b1 = Boolean("");              //false -- empty string var b2 = Boolean("JavaScript");    //true -- non-empty string var b3 = Boolean(100);             //true -- non-zero number var b4 = Boolean(null);            //false -- null var b5 = Boolean(0);               //false -- zero var b6 = Boolean(new Object());    //true -- object