I\'m fairly new to JS, and realize length is considered a property. But I received a comment to not use str.length in a loop:
for (i=0; i
Is
str.length
guaranteed constant time in JS too?
No, in fact there are no runtime performance or complexity guarantees in JavaScript whatsoever.
However, yes, it can be expected to be accessible in constant time, with no dynamic linear time length computation on access. The ECMAScript spec also describes the String .length property as immutable and that it is initialised when the string is constructed.