Reputation: 1753
Is there a shorthand syntax for the following JavaScript boolean ternary expression:
var foo = (expression) ? true : false
Upvotes: 1
Views: 406
Reputation: 664548
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;
Upvotes: 5