Skip to content

布尔值

一句话解释

布尔值 是 值 那个 是 要么 真 or 假, used for logical 操作 and conditionals.

用大白话说

布尔值是 primitive 值那个是 要么 true or false. Booleans are the foundation of conditional logic — if statements, while loops, and ternary operators all depend on boolean values.

JavaScript has six falsy values: 假, 0, "" (empty string), 空, undefined, and NaN. Everything else is truthy. This means 如果 ("hello") is true and 如果 (0) is false.

Comparison operators (===, <, >, <=, >=) return booleans. Logical operators (&&, ||, !) combine or invert boolean values. The 布尔值() function converts any value to its boolean equivalent.

示例

javascript
const isAdult = true;
const hasLicense = false;
console.log(isAdult && hasLicense); // false
console.log(isAdult || hasLicense);  // true
console.log(!isAdult);               // false

Logical 运算符 组合 布尔值 值 for conditional logic.

相关术语

相关资源

相关课程

  • 条件

    学习 关于 布尔值 in 条件.

解读错误信息

用大白话解释常见错误——什么意思、为什么发生、如何修复。

查看错误

← 返回术语表