And this is why I hate JavaScript...

Because stuff that works in some browsers, eg Firefox and Safari:

a = '123';
b = a[1]; // b is now '2', or undefined, take your pick...

...does NOT work in Internet Explorer. If you run the code above you’ll find that b ends up “undefined” in IE.

OK, so the “correct” code is pretty straightforward: use the charAt() function, or substr(), or one of a number of other solutions. But if you’re constantly working in other languages (eg. PHP) and just happen to have a need to write some quick JavaScript, it is extremely frustrating when you (A) use a language construct that works in so many other languages, (B) find that it works fine in your development environment and then (C) find that it doesn’t actually work fine when you test it in other environments. Grrrrr!

That’s my vent for the day. Back to work now...

EDITED TO ADD: And who the hell decided it would be a good idea to number months from 0-11 in JavaScript Date objects? Am I the only one that thinks that’s a DUMB idea? Days of the month are numbered 1-31. If some numbskull decided months should be numbered starting at 0, then why wasn’t that same rationale at least applied consistently to the day of the month? Not that I would want that, of course, I’m just saying...

Yet Another Programming Blog

Where James Gordon rambles about PHP and web development in general.

Find me on Twitter Find me on Stack Exchange Find me on Github Subscribe