At this point I always format if statements as if code block, because condition in if statement could be very long so that return would be lost dangling somewhere outside of field of view which could lead to bad mistakes.
functionfoo(arg){if(arg%3===0&&arg%5==0/* let's pretend there is very long condition*/)return'foobar'if(arg%3===0)return'foo'if(arg%5===0)return'foo'}
Data structures are good for reducing code's complexity. Sometimes it is clearer to use switch case or if's.
condition in if statement could be very long so that return would be lost dangling somewhere outside of field of view
I really couldn't agree more. This is definitely one of the main things that bother me about JS specifically — that there's no strict standard/expectation of writing really short code.
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.
This thing I use a lot!
At this point I always format if statements as if code block, because condition in if statement could be very long so that return would be lost dangling somewhere outside of field of view which could lead to bad mistakes.
Data structures are good for reducing code's complexity. Sometimes it is clearer to use switch case or if's.
I love these examples — thank you!