var s = new String("0123456789"); var c = s;
Much to my surprise, the code appeared to work just fine when compiled in ASP and it also worked in FireFox, Opera, Chrome and Safari, although failed in Internet Explorer.
Curious about the reasons this syntax didn't cause any errors, I sat down and read the ECMA Script specification for about an hour. There was nothing in the specification that would allow this syntax, even though the section 8.4 described string characters as UTF-16 code points stored in a sequence, which hinted towards C-style strings.
A character can be fetched from a string using bracket syntax, as for Array, no longer requiring an explicit call to the charAt method:
"ecmascript" // evaluates to "a"
Whew! It was driving me crazy! It turned out that all of the mentioned browsers just went for an early adoption of this syntax.
The first loop took 0.4 seconds to complete, while the second took 1.4 seconds in FireFox. Other browsers produced similar results. What a difference!