Skip to content

Instantly share code, notes, and snippets.


jdalton/hoisting-bounds-checks-1.js Secret

Last active Aug 29, 2015
What would you like to do?
// Hoist out the `array.length` load as if it’s stored in a
// variable to avoid repeat property access.
for (var sum = 0, i = 0; i < array.length; i++) {
// Avoid bounds check in the loop for index `i` of `array` by
// analyzing loop and pre-calculating the max possible `i` value.
sum += array[i];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment