Given:
(function() {
var items = [1, 2, 3, 4];
// In Chrome, this takes ~8-10 ms to execute.
for(var i = 0; i < items.length; i++) {
x(items);
}
// In Chrome, this takes 1-2 ms to execute.
for(var i = 0; i < items.length; i++) {
y();
}
function x(y) {
y[0] = -100;
}
function y() {
items[0] = 100;
}
})();
Why are the calls to x() 8-10 times slower than the calls to y()? Is it because variable resolution does not need to take place in the execution of y()?