Javascript三元布尔简写

时间:2019-06-28 19:02:33

标签: javascript conditional-statements ternary-operator

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

var foo = (expression) ? true : false

1 个答案:

答案 0 :(得分:5)

当然,您只想将表达式转换为布尔值:

var foo = Boolean(expression);

the same thing缩短为double not operators

var foo = !! expression;