Skip to main content
A Boolean in JavaScript is a primitive logical data type that represents one of two binary states: true or false. It serves as the foundational mechanism for evaluating logical expressions and representing binary conditions in memory.

Instantiation and Syntax

Booleans can be instantiated using literal notation or the global Boolean() function.

Primitive vs. Wrapper Object

JavaScript distinguishes between the boolean primitive type and the Boolean object wrapper. Using the new keyword invokes the constructor and creates an object reference rather than a primitive value. This alters strict equality evaluation and memory allocation.
Note: Instantiating Booleans via the new Boolean() constructor is considered an anti-pattern. Because objects are inherently truthy, new Boolean(false) evaluates to true in a boolean context.

Type Coercion and Truthiness

When a non-boolean value is evaluated in a boolean context, JavaScript performs implicit type coercion. Values are categorized strictly as either “truthy” or “falsy”. There are exactly eight falsy values in JavaScript. If a value is not on this list, it evaluates to true.
All other values, including empty arrays, empty objects, and the string "false", are truthy.

Logical Operators and Boolean Casting

JavaScript logical operators (&&, ||, !) interact directly with boolean logic. While && and || return the value of one of their operands based on short-circuit evaluation, the logical NOT operator (!) always coerces its operand to a boolean primitive and inverts it. Applying the logical NOT operator twice (!!) is a standard syntactic shorthand for casting a value to a boolean primitive, functionally identical to calling Boolean().
Tired of Poor JavaScript Skills? Fix That With Deep Grasping!Learn More