Skip to content

Commit

Permalink
Correction regarding loops and scope. There is no block scope without…
Browse files Browse the repository at this point in the history
… "let" in javascript. Example:

function foo() {
  for(var i = 0; i != 10; i++);
  console.log(i);
}
logs "10" to the console.
  • Loading branch information
bgruber authored and rmurphey committed Jun 17, 2010
1 parent 1f85072 commit eeb91fb
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions book/src/javascript-basics.xml
Expand Up @@ -360,9 +360,9 @@ for (var i=0; i<5; i++) {
console.log('try ' + i);
}</programlisting>
</example><remark>Note that in <xref
linkend="javascript-basics.examples.loops" /> we use the keyword
<token>var</token> before the variable name <varname>i</varname>. This
"scopes" the variable <varname>i</varname> to the loop block. We'll
linkend="javascript-basics.examples.loops" /> even though we use the keyword
<token>var</token> before the variable name <varname>i</varname>, this does
not "scope" the variable <varname>i</varname> to the loop block. We'll
discuss scope in depth later in this chapter.</remark></para>
</section>

Expand Down

0 comments on commit eeb91fb

Please sign in to comment.