JSLint imposes us to do manual hoisting of variables. What if we did it but at the end of the function? 😛

How you write

function print_array (array) {
  var length = array.length;
  for (var i = 0; i < length; ++i) {
    var elem = array[i];
    console.log(elem);
  }
}

How Javascript “rewrites” it

function print_array (array) {
  var length, elem, i;
 
  length = array.length;
  for (i = 0; i < length; ++i) {
    elem = array[i];
    console.log(elem);
  }
}

length = array.length;
for (i = 0; i < length; ++i) {
elem = array[i];
console.log(elem);
}
}

How we could write it!

function print_array (array) {
  length = array.length;
  for (i = 0; i < length; ++i) {
    elem = array[i];
    console.log(elem);
  }
 
  var length, elem, i;
}

var length, elem, i;
}

$(‘.highlightvar span:contains(var)’).css(‘background-color’, ‘yellow’).css(‘color’, ‘red’)

I have no idea if that could be of any use but it amused me 🙂

If you liked this article, you might be interested in my X feed as well.