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).
Log in to continue
We're a place where coders share, stay up-to-date and grow their careers.
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).