1

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

var foo = (expression) ? true : false
Dave Newton
  • 156,572
  • 25
  • 250
  • 300
  • 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
  • 572,313
  • 128
  • 898
  • 1,281