DEV Community

Discussion on: Better if statement w/ ternary operator ? : 💻

Collapse
 
bezo97 profile image
Zotya Docs

If we're really going for simplicity, in this particular case you can just say

adult = (age>=18)

since the A and B operations just give back the result of the condition.
Here's one example that better demonstrates the case:

result = (age>=18 ? "adult" : "young")

Cheers!

Collapse
 
link2twenty profile image
Andrew Bone

You don't need the brackets either 🙂