freeCodeCamp/guide/english/javascript/standard-objects/boolean/index.md

1.2 KiB

title
Boolean

Boolean

The Boolean object is an object wrapper for a boolean (true or false) value. You can explicitly define a Boolean as new Boolean([value]). The optional value argument is converted to a boolean value. If value is not specified, 0, -0, null, false, NaN, undefined, or the empty string (""), the object is set to false. All other values, including any object or the string "false", create an object with a value of true. An interesting exception is when DOM's document.all is passed as an argument to the Boolean constructor, it is evaluated as false1.

Boolean primitive value (true and false ) is not same as Boolean object values (true and false).

More Information:

The Difference Between Boolean Objects and Boolean Primitives in JavaScript -- A Drip of JavaScript

Sources

  1. You Don't Know JavaScript, Chapter 4, line :364. Accessed on October 31, 2017.