I ran into an unexpected behavior in both Chrome and the Node.js runtime today.
var x = 'I am a string';
console.log(x[0]); //String 'I'
console.log(x[0][0]); //String 'I'
console.log(x[0][0][0]); //String 'I'
I realize that accessing string indexes through brackets is not preferred and not universally supported, so my interest here is purely one of curiosity. What this implies to me is that strings are being built out of strings - ie, the character 'I' is itself a string with the character 'I' at index 0, which is itself a string... it's turtles all the way down.
Or this seems to imply to me that webkit just builds a new string object to return back to me every time I use the [] notation on an existing string. Both of those conclusions feel really weird to me.
Are either of them correct? What's going on under the hood when I call x[0]?
Edit: Related to below answer: Are strings object?