Yes, boolean is a primitive data type in JavaScript. It has exactly two values, true and false, and is the type produced by comparisons such as a > b and used by if, loops and logical operators. Do not confuse it with truthy and falsy values: many non-boolean values behave like false in a condition without being false.
This article covers the boolean type, conversion rules, the falsy list, and why new Boolean() is a trap.
A boolean is one of the seven JavaScript primitives, and typeof reports it as "boolean".
Booleans are immutable and compared by value. They are produced by comparison operators (===, !==, <, >=), by !, and by built-in predicates like Array.isArray() and Number.isFinite().
Conditions in if, while, for and the ternary operator evaluate any value as a boolean.
Logical operators &&, || and ?? do not always return a boolean. They return one of their operands: "a" && "b" is "b", and 0 || "fallback" is "fallback". Use !!value or Boolean(value) when you need a real boolean.
When JavaScript needs a boolean, it converts the value. Exactly these values are falsy:
| Falsy value | Type |
|---|---|
false | boolean |
0, -0, 0n | number, bigint |
"" (empty string) | string |
null | null |
undefined | undefined |
NaN | number |
Everything else is truthy, including "0", "false", [], {} and functions. The original claim that "non-empty objects and arrays" are truthy is correct, and note that an empty array is truthy too.
A frequent bug is testing if (count) when 0 is a valid value. Use count !== undefined or the nullish coalescing operator (count ?? 0) so 0 is not treated as missing.
Two idioms are common and equivalent:
String-to-boolean conversion is not automatic in the way many developers expect: Boolean("false") is true because the string is non-empty. Parse such strings explicitly.
JavaScript has a wrapper constructor, but new Boolean(false) creates an object, and every object is truthy.
Calling Boolean(value) without new is fine and returns a primitive. Never use new Boolean() in application code.
Short-circuit operators are the most common place where truthiness matters. || returns the first truthy operand, && returns the first falsy operand, and ?? only falls back when the left side is null or undefined.
Choose ?? for defaults when 0, "" and false are legitimate values. Logical assignment operators (||=, &&=, ??=) apply the same rules when assigning.
It is a primitive. Only the wrapper created with new Boolean() is an object, and you should avoid it.
Truthy. Only the values in the falsy table are falsy, so [] and {} both pass an if check. Check arr.length to test for emptiness.
x == true converts x to a number and compares it to 1, so "yes" == true is false even though "yes" is truthy. Prefer if (x) or x === true depending on what you mean.
The first ! converts the value to a boolean and negates it, and the second negates it back, giving the value's boolean equivalent.
Boolean is a primitive type with two values. Know the short list of falsy values, convert explicitly with Boolean(value) or !!value, parse strings yourself, and never use new Boolean().