Front end developer specialising in JavaScript and React. Experienced in all aspects of modern front end development. Passionate about making accessible, secure and performant software.
Personally I wouldn't use if / else statements for assignment. At least not very often:
If we are assigning multiple things inside the if / else statement, then we may lose track of one of them. It's less clear what's going on at first glance.
The declaration can be moved much further away, making things less clear.
We cannot use const, which gives us a guarantee of immutability (relatively speaking).
Having said that, I don't really remember having to conditionally assign multiple things...
However if I felt it was best, I would definitely replace ternary statements with if / else statements in other cases. Code readability and maintainability are extremely important. If you and your team believe that using if / else statements is best for that, then that's a very important consideration.
Completely agree with this. I always use const and resort to a mutable variable only if I cannot find a way around it. Variables that can be mutated add mental load and make the program harder to follow.
Personally I wouldn't use if / else statements for assignment. At least not very often:
const, which gives us a guarantee of immutability (relatively speaking).Having said that, I don't really remember having to conditionally assign multiple things...
However if I felt it was best, I would definitely replace ternary statements with if / else statements in other cases. Code readability and maintainability are extremely important. If you and your team believe that using if / else statements is best for that, then that's a very important consideration.
I definitely agree with you, I love using const, and if/elses take it away!
Thanks for reading!!
Completely agree with this. I always use const and resort to a mutable variable only if I cannot find a way around it. Variables that can be mutated add mental load and make the program harder to follow.
Thatβs definitely fair!!
Thanks for reading!