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, ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access