JavaScript variable scope can be particularly difficult to understand and get right. The situation gets even worse when you consider the _accidental_ creation of global variables, which is what happens when you declare a variable inside a function or the ``++for++`` clause of a for-loop without using the ``++let++``, ``++const++`` or ``++var++`` keywords.
``++let++`` and ``++const++`` were introduced in ECMAScript 2015, and are now the preferred keywords for variable declaration.
I modified the code sample you provided, [~linda.martin]. Feel free to change it back.
=== on 13 Mar 2015, 14:02:49 Linda Martin wrote:
\[~ann.campbell.2] From the description it seems that each type you declare a variable without the keyword "var" it creates a global variable. Whereas it is only within for-loops and functions that that it creates a global variable.
Maybe it's my understanding of english that it's questionable or I wrongly expressed myself when I first described the rule ?