Introduction

JavaScript, like any language, requires us to be judicious in the use of certain language features. Overuse of some features can decrease performance, while some techniques can be used to increase performance.

Remarks

Remember that premature optimization is the root of all evil. Write clear, correct code first, then if you have performance problems, use a profiler to look for specific areas to improve. Don’t waste time optimizing code that’s not affecting the overall performance in a meaningful way.

Measure, measure, measure. Performance can often be counter intuitive, and changes over time. What’s faster now might not be in the future, and can depend on your use case. Make sure any optimizations you make are actually improving, not hurting performance, and that the change is worthwhile.

Avoid try/catch in performance-critical functions

Limit DOM Updates

Benchmarking your code - measuring execution time

Cache (memoize) heavy-computing functions

Initializing object properties with null

Reuse objects rather than recreate

Prefer local variables to globals attributes and indexed values

Be consistent in use of Numbers