5 ms·
You're essentially correct; in JS, if you write for(var i = 0; i < arr.length; ++i) ... then the array's length is not read once at the beginning
by professoretc 3y ago
You're essentially correct; in JS, if you write
for(var i = 0; i < arr.length; ++i)
...
then the array's length is not read once at the beginning of the loop; it is read every loop iteration. So if the code inside the loop (or inside the getter for `length` itself) modifies the length of the array, then it will be caught when the condition is evaluated. The problem is that the C++ code makes assumptions about JS (reading the length of an array cannot change the array's length) that don't hold. But it's an easy mistake to make.