JavaScript has, as you might be aware, a specification called EcmaScript. The implementation (say v8) is indeed an interpretation of that specification, but this specification does dictate how all this is supposed to work, quite well. In this case, it even states that the specification doesn't specify howstrings are supposed to be stored. It also specifically states that the string "elements" are the UTF-16 integers that @dominela10
speaks about.
However, it also describes how the string iterator is different than the array iterator. To clarify: it specifically states that the string iterator iterates over codepoints, which is the closest thing to a character JavaScript has, which is not the same as a code element. To interpret a string as an array is therefore something that is indeed pretty careless.
Iterators are not Arrays, Arrays are, depending on the language, iterable, or yield an iterator; strings are, depending on the language iterable, or yield an iterator; iterators are iterable.
In that aspect, @adam_cyclones
you are correct that the string iterator is the same as an array iterator.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
JavaScript has, as you might be aware, a specification called EcmaScript. The implementation (say v8) is indeed an interpretation of that specification, but this specification does dictate how all this is supposed to work, quite well. In this case, it even states that the specification doesn't specify how
string
s are supposed to be stored. It also specifically states that the string "elements" are the UTF-16 integers that @dominela10 speaks about.ref: String Type
However, it also describes how the string iterator is different than the array iterator. To clarify: it specifically states that the string iterator iterates over codepoints, which is the closest thing to a character JavaScript has, which is not the same as a code element. To interpret a
string
as an array is therefore something that is indeed pretty careless.ref: String Iterator
Iterators are not Arrays, Arrays are, depending on the language, iterable, or yield an iterator; strings are, depending on the language iterable, or yield an iterator; iterators are iterable.
In that aspect, @adam_cyclones you are correct that the string iterator is the same as an array iterator.