Hey I am reading over this exercise, it keeps talking about how I was declared as 3 in the global scope, I see the Array and I see the loop that says to cycle through the array as long as i < 3. I dont see anywhere where I is equal to 3. Can you point me to where it is declared as 3 in global scope? thanks
-How does console.log(i) return 3?
var numArray = [];
for (var i = 0; i < 3; i++) {
numArray.push(i);
}
console.log(numArray);
// returns [0, 1, 2]
console.log(i);
// returns 3
I’ve edited your post for readability. When you enter a code block into the forum, precede it with a line of three backticks and follow it with a line of three backticks to make easier to read. See this post to find the backtick on your keyboard. The “preformatted text” tool in the editor (</>) will also add backticks around text.
Because the last time the for loop goes, i is equal to 2. But it hasn’t failed the test yet so it checks, it increments i to 3 and sees that i<3 is now longer true and exits the loop. So, at this point i is equal to 3.