DEV Community

Discussion on: What do you think about the ternary operator?

Collapse
 
twigman08 profile image
Chad Smith

As with everything in programming it has its place and can be used, as long as it is used right.

In languages where if's are only statements and not expressions then it becomes helpful. Of course don't abuse it. If you find yourself needing to write nested ternary operators then I would start thinking about refactoring that to a switch-case (or if-else if it's a string and the language doesn't support switch-case on string's).