How to use boolean casting function in Javascript?

Boolean() casting function

Boolean() casting function converts a value into its boolean equivalent. The following table lists the outcomes of Boolean() casting function:


Data Type True False

Boolean true false

String nonempty string empty string("")

Number    nonzero numberand infinity 0, NaN(NotANumber)

Object Any object null

undefined N/A Undefined

The following code converts a nonempty string to Boolean type:



        var aString = "Hello world!";

        var aBoolean = Boolean(aString);