Pay attention to the following points on the basis of understanding the scope chain:
1. Reading and Writing local variables in a function is always the fastest, while reading and writing global variables are usually the slowest. Remember that global variables always exist at the end of the context scope chain at runtime.
Rule of thumb: If a cross-scope value is referenced more than once in a function, it is saved to a local variable.
2. dynamic scope exists only inCodeDuring execution, it cannot be detected through static analysis. Several Keywords of static scope will be generated: With, try catch, and eval. dynamic scope is recommended only when necessary.
Try catch is generally within the catch code block, and all the local variables of the function will be placed in the second scope chain object.
Rule of thumb: You can minimize the impact of catch clauses on performance through simplified code. A good mode is to delegate errors to a function for processing.
3. Closure: If you need to frequently access a large number of cross-scope identifiers, each access will result in performance loss.
Rule of thumb: store common exaggerated variables in local variables and then directly access local variables.
Pay attention to these small details when writing code to improve code performance.