Too much Python makes Peter a shit Javascript developer

13 March 2009   0 comments   Javascript

Powered by Fusion×

This murdered a good half hour of my time splattered with lots of alert() statements to debug. Basically, in Firefox you can do this:

var word = "Peter";
alert(word[1]); // "e" in Firefox, undefined in IE

This is the wrong way to get to character in a string in Javascript. The correct way is to use charAt() like this:

var word = "Peter";
alert(word.charAt(1)); // "e" in Firefox and IE

I don't know about the other browsers but finally now works in IE7 too. I haven't even looked at it in IE6 and don't intend to either.


Your email will never ever be published

Related posts

Sandisk SSD v/s HDD 04 March 2009
Nginx vs. Squid 17 March 2009