Block Scope III

Let's take a look at one other common example of block scope, as defined within a for loop.

const cloudCount = () => { let i = 2; console.log(i); // 2 for (let i = 0; i < 10; i++) { console.log(i); // Numbers from 0 to 9 } }; cloudCount(); console.log(i); // ReferenceError
  1. Here the variable i is defined in the cloudCount() function.
  2. Within the for loop block, we again define i, as a value that will be incremented.
  3. The local value of i, whether defined in the function block or the for loop, has no impact on the global scope of our program.
Community Forums
Get help and ask questions in the Codecademy Forums
Report a Bug
If you see a bug or any other issue with this page, please report it here.