简体   繁体   English

Javascript三元布尔简写

[英]Javascript ternary boolean shorthand

以下JavaScript布尔三元表达式是否有速记语法:

var foo = (expression) ? true : false

Sure, you just want to cast your expression to a boolean: 当然,您只想将表达式转换为布尔值:

var foo = Boolean(expression);

or the same thing shortened to double not operators : 同一件事简化为非运算符的两倍

var foo = !! expression;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM