Skip to content
loading...

re: Here are Top 5 Best Practices for JavaScript you MUST ALWAYS FOLLOW VIEW POST

FULL DISCUSSION
 

This is a neat post. Here are some of my initial takeaways:

This feature is known as Automatic Semicolon Insertion. However, using this feature is not recommended

While I agree with you that you should not rely on ASI, it's really all up to whomever is writing the code. A lot of other people have pointed out that just because Google's style guide dictates that you should not rely on ASI doesn't mean that it is now written in stone. For some more information on why you should / shouldn't use ASI, check out this read for more information. It has a lot of good points, and only helped to reinforce the reasoning behind why I do not use ASI.

Reusing any piece of code? Make it a function.

Any piece of code? You mentioned that even if you only use a snippet twice, you should function-ify it. While I'm all for cutting down on code re-use, if we were to abstract every segment of code away into functions... Well, now, what would that do for your program's readability? 🤔

Make your code concise wherever possible.

I tend to agree with this one as well, but with a huuuuuuuuge caveat: keeping your code consistent is as important, if not more, than keeping your code concise. You mention removal of the brackets as one way to help improve readability and limit redundancy.

Humans, however, have a much easier time reading when there are detectable patterns (consistent use of brackets is a good example of this). When you do not follow a pattern, reasoning about the code becomes decidedly more difficult. While I have other opinions about keeping if statements on one line, I almost always use the optional curly brackets. I would argue that omitting the curly brackets does little to improve readability. Often times, I would argue the inverse 😅

On the whole, while I certainly agree that a lot of these concepts are important to learn, only some of them pertain directly to Javascript. Things like abstracting reused code into functions and keeping things concise and consistent are just best practices when it comes to programming at large.

code of conduct - report abuse