📄️ Benchmarking your code - measuring execution time
Most performance tips are very dependent of the current state of JS engines and are expected to be only relevant at a given time. The fundamental law of performance optimization is that you must first measure before trying to optimize, and measure again after a presumed optimization.
📄️ Be consistent in use of Numbers
If the engine is able to correctly predict you're using a specific small type for your values, it will be able to optimize the executed code.
📄️ Limit DOM Updates
A common mistake seen in JavaScript when run in a browser environment is updating the DOM more often than necessary.
📄️ Prefer local variables to globals, attributes, and indexed values
JavaScript engines first look for variables within the local scope before extending their search to larger scopes. If the variable is an indexed value in an array, or an attribute in an associative array, it will first look for the parent array before it finds the contents.
📄️ Use a memoizer for heavy-computing functions
If you are building a function that may be heavy on the processor (either clientside or serverside) you may want to consider a memoizer which is a cache of previous function executions and their returned values. This allows you to check if the parameters of a function were passed before. Remember, pure functions are those that given an input, return a corresponding unique output and don't cause side-effects outside their scope so, you should not add memoizers to functions that are unpredictable or depend on external resources (like AJAX calls or randomly returned values).
📄️ Memory Efficiency
Drawback of creating true private method
📄️ Initializing object properties with null
All modern JavaScript JIT compilers trying to optimize code based on expected object structures. Some tip from mdn.
📄️ Reuse objects rather than recreate
Example A
📄️ Avoid try/catch in performance-critical functions
Some JavaScript engines (for example, the current version of Node.js and older versions of Chrome before Ignition+turbofan) don't run the optimizer on functions that contain a try/catch block.