Ternary operators are not a shortcut nor replacement for If/else statements. Ternaries are okay when you need to return something based on condition, and you want to write it as oneliner. They are okayish in React too (as we can't use if/else in jsx). Besides this ternaries can get hard to read and hard to maintain pretty fast, so I think that overusing them would be a really bad idea.
There's even Eslint rule for disallowing nested ternaries 🙂
In the end, it's only important that a programmer knows what syntax to use in what situation.
Yes, you're absolutely right! The article wasn't meant to "replace if statements", but shed light on it being a possible option for using conditional operators :) And thanks for highlighting the fact that it shouldn't be overused. I have included it in the post
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Ternary operators are not a shortcut nor replacement for If/else statements. Ternaries are okay when you need to return something based on condition, and you want to write it as oneliner. They are okayish in React too (as we can't use if/else in jsx). Besides this ternaries can get hard to read and hard to maintain pretty fast, so I think that overusing them would be a really bad idea.
There's even Eslint rule for disallowing nested ternaries 🙂
In the end, it's only important that a programmer knows what syntax to use in what situation.
Yes, you're absolutely right! The article wasn't meant to "replace if statements", but shed light on it being a possible option for using conditional operators :) And thanks for highlighting the fact that it shouldn't be overused. I have included it in the post