Casting to Boolean value : Type Conversion : Number Data Type JAVASCRIPT TUTORIALS


JAVASCRIPT TUTORIALS » Number Data Type » Type Conversion »

 

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


  1. the value is an empty string,

  2. the number 0,

  3. undefined, or

  4. 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







HTML code for linking to this page:

Follow Navioo On Twitter

JAVASCRIPT TUTORIALS

 Navioo Number Data Type
» Type Conversion