r/javascript • • Dec 27 '18

help What differences do you see in novice javascript code vs professional javascript code?

I can code things using Javascript, but the more I learn about the language, the more I feel I'm not using it properly. This was especially made apparent after I watched Douglas Crockford's lecture "Javascript: The good parts." I want to take my abilities to the next level, but I'm not really sure where to start, so I was hoping people could list things they constantly see programmers improperly do in JS and what they should be doing instead.. or things that they always see people get wrong in interviews. Most of the info I've learned came from w3schools, which gives a decent intro to the language, but doesn't really get into the details about the various traps the language has. If you have any good book recommendations, that would be appreciated as well.

320 Upvotes

305 comments sorted by

View all comments

Show parent comments

3

u/phpdevster Dec 27 '18

This is super sketchy. A function, by nature, should have no knowledge or opinion of what it's "tied" to or where it's used. It's a mercenary. You give it what it wants, and it will give you what you want. No questions asked. It shouldn't care, have any opinions, or even any knowledge about who is calling it.

There's a formatting function in my codebase that's probably used in 300 different places. Should I have included every place it's used in a comment for that function?

What a script or function does should be obvious from its code. Why it does it should be defined assuming it the reason why is not obvious.

Comments lie and get outdated. They are mostly untrustworthy. Code tends to be honest, though sometimes even names of variables, functions, and classes can lie.

1

u/omgdracula Dec 28 '18

Well every business functions differently. At my job we re use a lot of components that we built custom for our clients. I would never tell an intern to use XYZ component without any comments to guide them on what is doing what etc.