DEV Community

Discussion on: What in the IF is a ternary?

Collapse
 
joelnet profile image
JavaScript Joel

It's worth noting that ternaries work in setting values not executing statements.

if(something) {
  doAThing();
} else {
  doAnotherThing();
}

can't be reduced to

something ? doAThing() : doAnotherThing();

There's nothing that would prevent a ternary from executing statements. That statement is perfectly valid JavaScript.

// VALID: You can also use a ternary to execute functions!
something ? doAThing() : doAnotherThing();
Collapse
 
itsasine profile image
ItsASine (Kayla)

Really? I never saw that as a valid option in IntelliJ within the Jasmine/ES5 realm :o Nice!