Some JavaScript practices
- It is best to declare variables in one statement, i.e. use the single
var
pattern. - Avoid
eval
. Use$.parseJSON()
. - Pass arguments as objects rather than individual variables
- Take care to structure your function body properly, or else you’ll fall prey to
hoisting
. Declaring local variables anywhere with a function body would automatically hoist them to the top. - Make use of the memoization pattern to reduce re-computation. I found it very useful when working with d3.js
- You need not use
document.ready
if you’re including your scripts at the bottom already.
More to come…