I haven't done serious JavaScript programming in a while, and I am writing an intro guide to the language for some of my colleagues. I'd like to discuss loop best practices, but there is one small detail I've kept in the back of my head:
When looping over arrays, I remember the following pattern not being safe to use because there are major browsers that don't support it:
for (var i = 0; i < ls.length; i++) { ... }
Instead, the var keyword must be moved out of the array, as such:
var i;
for (i = 0; i < ls.length; i++) { ... }
Is this correct? I've scoured the net and cannot confirm this. Do some old browsers not support the first method? If not, which ones do not?