DEV Community

Discussion on: JavaScript Best Practices for Beginners

Collapse
 
xavierbrinonecs profile image
Xavier Brinon

That's what standardjs.com/ and prettier.io/ are for I guess.

I tend to format code the way I like before starting reading it, so the original styling is gone anyway.

Devs should focus more on making the code readable to other humans first; spend some time finding the most relevant names. Show the intent and make the context of the code obvious. The comments should be about the why not the how. Always name your functions. Be as declarative as possible, don't try to go for the creative solution if that makes it unreadable (I assume everybody should know how to read an Array.reduce... 👍🏻 ).

Technically you should use === when you are not sure about the types of what you are comparing. If you know them, == is perfectly fine. Based on the specs === switches to == when the 2 values are of the same types. I linter forces the === anyway 🤷🏻‍♂️

I don't see why an IFFE is best practice btw.

A best practice I like to add is to follow the new features appearing every year as they tend to make the code more declarative. I get sad everytime I see a index === -1.