Javascript - Boolean (Truthy|Falsy)


Data Type - Boolean in Javascript.


var myVariable = true;

Truthy / Falsy

JavaScript defines a list of specific values that are considered “falsy” because when coerced to a boolean, they become false. Any other value not on the “falsy” list is automatically “truthy” — when coerced to a boolean they become true. Truthy values include things like 99.99 and “free”.

Truthy Falsy
Evaluate to true Evaluate to False
true false
Non-zero number 0 (zero)
“Non Empty String” “” (empty string)
Objects null
Array undefined
Functon NaN

Example: Operators such as if, ||, and && work with any values thanks to this coercion:

x = [true, false, 0, 3, "Non-Empty","", null, {}, undefined, [], NaN, function(){} ];

for (i in x) {
   if (x[i]) {
     console.log(x[i]+" is True");
   } else {
     console.log(x[i]+" is False");


From String

let booleanValue = (value === 'true');




console.log(typeof true);

Documentation / Reference

Powered by ComboStrap