for vs function

Edit on GitHub

Setup

var array = [];
var length = 500
for(var i=0; i<length; i++) {
array.push(i);
}
var goal = length;

Tests

  • for

    for(var i=0; i<length; i++) {
    (array[i] === goal) && break;
    }
  • function

    var temp = (i) => array[i] === goal;
    for(var i=0; i<length; i++) {
    temp(i) && break;
    }