企业🤖AI Agent构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
# TypeScript 逻辑运算符 > 原文: [https://howtodoinjava.com/typescript/logical-operators/](https://howtodoinjava.com/typescript/logical-operators/) TypeScript 逻辑运算符类似于您在 JavaScript 逻辑运算符中学习的内容。 这些运算符有助于比较布尔表达式并产生单个布尔值作为结果。 ## 逻辑运算符 逻辑 AND 运算符 – `&&` 如果两个操作数(或表达式)均为`true`,则结果将为`true`,否则为`false`。 ```java let firstVar = true; let secondVar = false; console.log( firstVar && secondVar ); //false console.log( firstVar && true ); //true console.log( firstVar && 10 ); //10 which is also 'true' console.log( firstVar && '10' ); //'10' which is also 'true' ``` > 阅读更多:[真值和假值](https://howtodoinjava.com/typescript/truthy-and-falsy/) 逻辑或运算符 – <code>&#124;&#124;</code> 如果两个操作数(或表达式)中的任何一个为`true`,则结果将为`true`,否则为`false`。 ```java let firstVar = true; let secondVar = false; console.log( firstVar &#124;&#124; secondVar ); //true console.log( firstVar &#124;&#124; true ); //true console.log( firstVar &#124;&#124; 10 ); //true console.log( firstVar &#124;&#124; '10' ); //true ``` 逻辑非运算符 – `!` 它用于反转其操作数的逻辑状态。 它将`true`转换为`false`,反之亦然。 ```java let firstVar = 10; let secondVar = 20; console.log( !true ); //false console.log( !false ); //true console.log( !firstVar ); //false console.log( !null ); //true ``` 将我的问题放在评论部分。 学习愉快!