Introduction
JavaScript offers powerful techniques that can be used to to do very complex tasks in one line, these can be called one-lin...
For further actions, you may consider blocking this person and/or reporting abuse
Please never use chaining in ternary operators because it's hard to follow and can lead to errors.
They are not more difficult to read than the 8f-else-if chains
Right off the bat the nested ternaries should be considered a crime
No, they shouldn't
Totally agree but its still a valid one liner in js :)
Can you elaborate please, i'm new to programming, and would love to know why.
Thank you.
the danger is precedence order of the operations in the ternary operator expression.
expressions should be put in parantheses.
Thank you!
might have to update your article. swapping values with const won't work... this could be misleading for someone starting fresh.
also I don't agree with the use of chaining ternary operator like others. but it could be just my perspective.
anyways, good luck!
That ternary chaining is absolutely horrible for readability.
Done Thanks a lot!
Swapping values using destructuring with const
🫣🥶
Did you even test that?
yes it works but the only thing that needs to change is
let
instead ofconst
That's my point... Not tested. Maybe even AI generated....
No it doesn't
It would return a SyntaxError because
a
is already declared.That was a mistake since i mostly use const while creating variables so yeah it was a habit of using const there, fixing it now, Thanks!
I don't that use const as much as I should :).
and prefer dynamic typing, for creativity.
If the dude doesn't know the difference between let and const, it's better to forgo the whole article, sadly.
It was a mistake! Fixing it now :)
If you're a fresh coder right out of college or maybe a deep back-end dev who is just starting to mess with front end, and you ever give me a nested ternary like that in a pull request, I will come to your place, wherever you live, off-shore, domestic, doesn't matter, and I will punch you directly in the mouth.
in the face*
thank you Shubh, my friend.
your list is reconforting, and definitely good to know :).
about the chained ternary operations, precedence should be taken care of.
You have to be trolling with the chained ternaries…. right? No one writes code like this in the real world.
I have seen that happen in react code while rendering multiple possible jsx code