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.

GroupBasic Types
KindType
Strict modeNot 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

!!xIn 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.
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.
Web-Tutorial.com

Web-Tutorial Tech Team

A team of developers maintaining programming tutorials. Each tutorial is written and reviewed by developers with expertise in that field. We work to keep our content accurate and reliable — if you spot an issue, please let us know.

100%

🙏 帮我们做得更好

我们是刚上线的编程教程站,几个人的小团队,精力有限。页面虽经检查,难免还有疏漏——链接失效、排版错乱、内容有误、语言生硬……

如果您发现了,麻烦告诉我们,我们会在收到反馈后第一时间进行修复,再次感谢您的光临 🙏