===Boolean===
[[JavaScript]] provides a [[Boolean data type]] with <tt>{{mono|true</tt>}} and <tt>{{mono|false</tt>}} literals. The typeof operator returns the string <tt>{{mono|"boolean"</tt>}} for these [[primitive types]]. When used in a logical context, <tt>{{mono|0</tt>}}, <tt>{{mono|-0</tt>}}, <tt>{{mono|null</tt>}}, <tt>{{mono|NaN</tt>}}, <tt>{{mono|undefined</tt>}}, and the empty string (<tt>{{mono|""</tt>}}) evaluate as <tt>{{mono|false</tt>}} due to automatic [[type coercion]]. The [[complement (set theory)|complement]] evaluates as <tt>{{mono|true</tt>}}, including the strings <tt>{{mono|"0"</tt>}}, <tt>{{mono|"false"</tt>}} and any object (except <tt>{{mono|null</tt>}}). Automatic type coercion by the equality comparison operators (<ttcode>==</ttcode> and <ttcode>!=</ttcode>) can be avoided by using the type checked comparison operators, (<ttcode>===</ttcode> and <ttcode>!==</ttcode>).
When type conversion is required, JavaScript converts <tt>{{mono|Boolean</tt>}}, <tt>{{mono|Number</tt>}}, <tt>{{mono|String</tt>}}, or <tt>{{mono|Object</tt>}} operands as follows:<ref>{{cite web | url=https://developer.mozilla.org/en/JavaScript/Reference/Operators/Comparison_Operators | title=Comparison Operators - MDC Doc Center | publisher=Mozilla | date=5 August 2010 | accessdate=5 March 2011}}</ref>
;{{small|Number and String}}: The string is converted to a number value. JavaScript attempts to convert the string numeric literal to a Number type value. First, a mathematical value is derived from the string numeric literal. Next, this value is rounded to nearest Number type value.
;{{small|Boolean}}: If one of the operands is a Boolean, the Boolean operand is converted to 1, if it is <tt>{{mono|true</tt>}} or to 0, if it is <tt>{{mono|false</tt>}}.
;{{small|Object}}: If an object is compared with a number or string, JavaScript attempts to return the default value for the object. An object is converted to a primitive String or Number value, using the <tt>{{mono|.valueOf()</tt>}} or <tt>{{mono|.toString()</tt>}} methods of the object. If this fails, a runtime error is generated.
[[Douglas Crockford]] advocates the terms "truthy" and "falsy" to describe how values of various types behave when evaluated in a logical context, especially in regard to edge cases.<ref>{{cite web | url=http://javascript.crockford.com/style2.html | title=The Elements of JavaScript Style | publisher=Douglas Crockford | accessdate=5 March 2011}}</ref>
The binary logical operators returned a Boolean value in early versions of JavaScript, but now they return one of the operands instead. The left–operand is returned, if it can be evaluated as : <tt>{{mono|false</tt>}}, in the case of [[logical conjunction|conjunction]]: (<ttcode>a && b</ttcode>), or <tt>{{mono|true</tt>}}, in the case of [[logical disjunction|disjunction]]: (<ttcode>a || b</ttcode>); otherwise the right–operand is returned. Automatic type coercion by the comparison operators may differ for cases of mixed Boolean and number-compatible operands (including strings that can be evaluated as a number, or objects that can be evaluated as such a string), because the Boolean operand will be compared as a numeric value. This may be unexpected. An expression can be explicitly cast to a Boolean primitive by doubling the logical [[negation|negation operator]]: (<tt>{{mono|!!</tt>}}), using the <tt>{{mono|Boolean()</tt>}} function, or using the [[Conditional (programming)|conditional operator]]: (<ttcode>c ? t : f</ttcode>).
<div style="font-size:85%;line-height:150%;">
</div>
The new operator can be used to create an object wrapper for a Boolean primitive. However, the typeof operator does not return <tt>{{mono|boolean</tt>}} for the object wrapper, it returns <tt>{{mono|object</tt>}}. Because all objects evaluate as <tt>{{mono|true</tt>}}, a method such as <tt>{{mono|.valueOf()</tt>}}, or <tt>{{mono|.toString()</tt>}}, must be used to retrieve the wrapped value. For explicit coercion to the Boolean type, Mozilla recommends that the <tt>{{mono|Boolean()</tt>}} function (without <tt>{{mono|new</tt>}}) be used in preference to the Boolean object.
<div style="font-size:85%;line-height:150%;">
|