-1

Is there an idiomatic way to write the conditional operator when you want nothing to happen in one case?

For example, in the following I want to yield a value only if foo is truthy.

Syntactically I must include the second half of the conditional operator (the :), so is it idiomatic to put undefined here?

foo ? yield 'something' : undefined;
Ben Aston
  • 53,718
  • 65
  • 205
  • 331

1 Answers1

3

No. You can't.

If you do not want to happen nothing just go with simple if.

if(foo)
 yield 'something'
Suresh Atta
  • 120,458
  • 37
  • 198
  • 307