Using Local Function Variables
optimization
by sirfizx
JavaScript
// i is in global namespace
t0 = new Date();
var i;
for (i=0; i<1000000; i++);
t1 = new Date();
// i is in local namespace
function count() {
var i;
for (i=0; i<1000000; i++);
}
count();
t2 = new Date();
d = document;
d.write('Without local variables = ', t1-t0, '<br />');
d.write('With local variables = ', t2-t1, '<br />');