2 ms·
> That is how JavaScript "Array" objects work. Array indexes are coerced to a strings, as they are for all objects. Well, according to the spec. All modern VMs
by vanderZwan 8y ago
> That is how JavaScript "Array" objects work. Array indexes are coerced to a strings, as they are for all objects.
Well, according to the spec. All modern VMs make optimisations for small integers, which is allowed as long as the behaviour is in accordance to the spec.
- arghwhat 8y agoOf course, but the language spec severely limit what optimizations can be done. For example, V8 will happily give you a proper array if certain criteria is met, but it must always be ready for you trying to index it with a string, which means that it must attempt to parse the string as a numeric value. This means deoptimization checks, or in the worst case, a non-optimized array.