strings , and any object. Type conversion Automatic type coercion by the equality comparison operators (== and !=) can be avoided by using the type checked comparison operators (=== and !==). When type conversion is required, JavaScript converts , , , or operands as follows: 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. If one of the operands is a Boolean, the Boolean operand is converted to 1 if it is , or to 0 if it is . 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 or 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. 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 : , in the case of conjunction: (a && b), or , in the case of disjunction: (a || b); 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 operator: (), using the function, or using the conditional operator: (c ? t : f). // Automatic type coercion console.log(true == 2 ); // false... true → 1 !== 2 ← 2 console.log(false == 2 ); // false... false → 0 !== 2 ← 2 console.log(true == 1 ); // true.... true → 1 === 1 ← 1 console.log(false == 0 ); // true.... false → 0 === 0 ← 0 console.log(true == "2"); // false... true → 1 !== 2 ← "2" console.log(false == "2"); // false... false →