length variable of type
Number. This length is automatically updated as the array is updated to the number of elements in the array.
Number class. We know that floating point arithmetic cannot exactly represent all integers within its range.
So my question is, what happens with large arrays, where
length + 1 cannot exactly represent the next largest integer in the sequence?
According to this the maximum length of an Array is
9,007,199,254,740,991 so you won't have to worry because the engine won't let you get that far, example:
new Array(4294967296); // RangeError: Invalid array length
Relevant part of the spec:
- c. Let newLen be ToUint32(Desc.[[Value]]).
b. If newLen is not equal to ToNumber( Desc.[[Value]]), throw a RangeError exception
So given our example length
var length = 4294967296; var int32length = length >>> 0; // Convert to int32 int32length === 0; // Can't represent this as int32 length !== int32length; // Therefore RangeException
so I guess @RGraham is right