Ternaries as shown here are mostly fine.
I use them mostly to provide variables with (default) values which come in a binary flavor.
For functions I prefer
chrisPratt = (marvel)=>{ if(marvel) return "I am Star-Lord!"; return "Have you watched Guardians of the Galaxy?"; };
because your eyes rest on the condition and it is easy from that to look at the non matching case.
But I admit, this has more to do with personal taste ;)
You should add a warning sign not to overuse ternaries, esp. start nesting those guys. This could end up pretty nasty.
Thanks for highlighting it. I have included it in the post.
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
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.
Ternaries as shown here are mostly fine.
I use them mostly to provide variables with (default) values which come in a binary flavor.
For functions I prefer
chrisPratt = (marvel)=>{
if(marvel) return "I am Star-Lord!";
return "Have you watched Guardians of the Galaxy?";
};
because your eyes rest on the condition and it is easy from that to look at the non matching case.
But I admit, this has more to do with personal taste ;)
You should add a warning sign not to overuse ternaries, esp. start nesting those guys. This could end up pretty nasty.
Thanks for highlighting it. I have included it in the post.