Evaluating local variables

As we have seen in the previous example, omitting the let or var keyword in front of the declaration of a local variable makes it global. In all cases, functions and objects should not be able to create functional side effects by modifying the value of variables outside of their local scope. Thus, the let keyword should always be used when declaring variables inside the scope of a function or structure. For example, simply moving global variables to the local scope of a function that is using them within a local loop translates into almost a 30% increase in performance in most browsers.

Also, when declaring variables with the let keyword, you get to use block scope, which should be used as much as possible. Thus, ...

Get Mastering The Faster Web with PHP, MySQL, and JavaScript now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.