News for hackers. Stuff that matters.
Re:Using const/let instead of var can make JavaScript code r... by mantap on Wednesday October 21, 2020 @07:49AM (#24846855)
It can only hoist the length out of a for loop if it can prove that the length doesn't change, i.e. the array isn't modified. Otherwise it does have to check it each iteration. This is pretty hard in general since any time you call an external function it could potentially have a reference to the array and modify it.

I suspect the length access is just so fast that the difference between hoisting it out and not is immeasurable.

There are no comments on this comment yet.