Avoid unnecessary DOM interactions:
Use DOM objects only to store info that directly affects how the DOM lays out or draws elements.
Optimize property access:
Don’t delete properties:
It might seem useful to add temporary properties to objects and delete them later after you don’t need them anymore. But this is a bad practice because it can greatly degrade performance.
Structure objects correctly:
Add properties to object instances, but add methods to the object prototype. Methods added to instances as inner functions of the constructor become closures that capture the activation context of the constructor. Consequently, a new closure object must be allocated for every such method, every time a new object is constructed. This pattern is often used as an encapsulation mechanism to implement private properties and methods,
Use integer arithmetic where possible:
Avoid floating point value boxing:
The previous section mentioned the problem of floating point value boxing: any time a floating point number is assigned to a property of an object or an element of an array, it must first be boxed (allocated on the heap). If your program performs a lot of floating point math, boxing can be costly. You can’t avoid boxing when working with object properties, but when operating on arrays, you can use typed arrays to avoid boxing.
Move anonymous functions to global scope :
It’s common to use anonymous functions to bind event handlers to DOM events, complete asynchronous work (via promises or other asynchronous completion patterns), or process array items using the Array for each method. When using anonymous functions, it’s good to be aware of the cost associated with closures.
Much like methods defined on object instances (earlier in this document), anonymous functions are closures that capture the activation context of the enclosing function. A new closure object must be allocated every time the enclosing function is called. Consequently, if the enclosing function is called often (as in the next example) and the anonymous function is relatively small, the overhead of allocating a closure object can be significant.