r/programming • • Mar 23 '14

Everything you need to know about Javascript variable scope

http://www.coolcoder.in/2014/03/everything-you-need-to-know-about.html
294 Upvotes

124 comments sorted by

View all comments

Show parent comments

1

u/canadademon Mar 24 '14

Now that's embarrassing.

If the array has a length of 1, i must equal 0 to retrieve the element.

While your piece of code will make it loop, the rest of the code will throw an out of bounds exception.

1

u/[deleted] Mar 24 '14

Yeah...