I really appreciate and identify with this article.
But... Not the nested ternaries. The example used as the "bad nested if" feels to me like those commercials for cracking eggs and how no one can do it (meaning, it's actually easy, but we want to sell you a thing)
First, let's kill the unneeded semicolons, because, yuck. Second, reverse the first logic and use else if for the second and you have yourself some pretty simple logic that can also be multiple lines long... but... for the sake of this example we don't need curly braces either. So apples to apples if code would be below. Honestly, the nested ternary functions I've seen are a HUGE mess, not at all as simple as the example provided. Especially while returning JSX and returning blocks of JSX-HTML...shudder
if(!conditionA){result='value: Not A'console.log('not A')}elseif(conditionB){result='A & B'console.log('value: A & B')}else{result='A'console.log('value: A')}
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.
I really appreciate and identify with this article.
But... Not the nested ternaries. The example used as the "bad nested if" feels to me like those commercials for cracking eggs and how no one can do it (meaning, it's actually easy, but we want to sell you a thing)
First, let's kill the unneeded semicolons, because, yuck. Second, reverse the first logic and use
else if
for the second and you have yourself some pretty simple logic that can also be multiple lines long... but... for the sake of this example we don't need curly braces either. So apples to apples if code would be below. Honestly, the nested ternary functions I've seen are a HUGE mess, not at all as simple as the example provided. Especially while returning JSX and returning blocks of JSX-HTML...shudderMulti-line Version