boolean Boolean Type
Last updated: 2026-10-22
boolean Boolean Type
boolean has exactly two values, true and false. Use it for feature flags, conditions and comparison results.
| Group | Basic Types |
|---|---|
| Kind | Type |
| Strict mode | Not required |
ℹ️ Info The editor transpiles TypeScript to JavaScript and runs it (no type checking); see each example's Output for type-check results.
📝 Syntax
let isOpen: boolean = true;
let result = 3 > 5; // false
let flag = Boolean("text"); // true
⚙️ Parameters
| !!x | In boolean contexts, 0, "", null, undefined and NaN are falsy; everything else is truthy |
|---|
Returns:None — boolean is a basic type annotation and produces no runtime code.
▶ Example
Edit the code below and click Try it to see the transpiled result:
Output:
false
true false
(Runtime output after transpilation; note Boolean("false") is true — any non-empty string is truthy)
💡 Notes
⚠️ Note Boolean("false") is true — every non-empty string is truthy. String-based flags (like "0") must be compared explicitly, never Boolean-ified.
💡 Tip Return real booleans (comparison expressions or explicit true/false), not "yes"/0 values that rely on implicit conversion.
🏷️ Related Basic Types
💡 Related cases
More cases coming soon.
📚 Related tutorials
❓ FAQ
Q Boolean() vs new Boolean()?
A Boolean(x) converts and returns a primitive boolean; new Boolean(x) creates a wrapper object that is always truthy — never use the latter.
Q Why is Boolean("false") true?
A Conversion only checks non-emptiness, not meaning. Any non-empty string (including "false" and "0") is truthy.
Q Does a && b always yield a boolean?
A No — && and || return one of their operands (short-circuit). Wrap with Boolean() or use a comparison for a strict boolean.