I thought I’d share a bit of JavaScript or a little Got-Me, consider the following;
function A()
{
for (index = 0; index < 10; index++)
{
alert(index);
B();
alert(index);
}
alert(‘finish’);
}
function B()
{
for (index = 0; index < 10; index++)
{
// do nothing
}
}
I ran this on Firefox/Safari and got….
0,9, finish
I was surprised on two counts, 1. Why didn’t the for loop work? 2. Why the shared scope? Anyway assuming I had accidentally created a global I corrected it and it worked as expected…
for (var index = 0; index < 10; index++)