1

Is there a shorthand syntax for the following JavaScript boolean ternary expression:

var foo = (expression) ? true : false
Dave Newton
  • 158,873
  • 26
  • 254
  • 302
  • See https://stackoverflow.com/questions/784929/what-is-the-not-not-operator-in-javascript –  Jun 28 '19 at 19:04

1 Answers1

5

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;
Bergi
  • 630,263
  • 148
  • 957
  • 1,375