Prevents unnecessary checking of var length

The js engine will check the var each time, but since the length will
not change why not just use a var to increase speed

Fixes loop, in chance var doesn't declare first