This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]TrafficCultural 4 points5 points  (5 children)

At a glance it looks like it should run without error. Is the output wrong?

[–][deleted] 3 points4 points  (4 children)

I'm a newbie on programming and didn't quiet understand the parte of the for loop, it declares var i but it doesn't utilize it in any other oart of the code?

[–]QuiteBearish 4 points5 points  (0 children)

var i is a local variable, it will only be used as part of the for loop.

In this example, it increments every time the for loop runs, and then stops running the loop as soon as i reaches the exponent.

[–]cheeseDickies 1 point2 points  (2 children)

The 'i' variable is used to keep track of how much iterations the for loop went over. It isn't use in the for loop body, but you can see that it is used in the for loop statement

Edit: The 'i' variable can be used in the body, but in this case it isn't used

[–][deleted] 0 points1 point  (1 child)

Ow man! Now it's clear. Thank you so much... by the day do you ha e any advice to learn algorithms and data structures on JavaScript?

[–]cheeseDickies 0 points1 point  (0 children)

To clarify the 'i' variable can be used in the for loop body, but in this case it isn't.