A weblog by Will Fitzgerald

number + string

So, I’m doing what I thought would be a small browser-based project (kindof ‘Ajaxy’), but it turns out to be taking longer than I thought it would. Things are better than there were when I last did heavy web-dev work, especially considering that I am not worrying about being compatible with anything other than the latest FIrefox or Safari releases. But I’m writing a lot of Javascript, and it feels a bit like going back to the mid-80s, and I’m having to remember certain caveats that I haven’t had to thing about in a long time.

Fer instance: automatic conversion of strings to numbers. What happens when evaluating 10 + "10"? I wish I could have the four hours of my life back that I spent tracking down a bug which turned out to be caused by my forgetting this was a problem. (I was reading in an XML file, which included digits that Javascript wasn’t converting to numbers as I assumed. Grr, I have a PhD in computer science and I (was stupid enough to forget this | have to deal with ‘stone knives and bearskins’)?

Note to self: Javascript converts numbers to strings when using ‘+’ (which adds numbers, but concatenates strings); for other math operations, it converts strings to numbers.

1 + 1 + "1"
"10" * "5"

I was explaining to Bess, my wife, what the problem was, and she didn’t seem to be listening, so I apologized for boring her. She said that it wasn’t that so much, but that she just didn’t understand the technical issues. I assured her that if she did understand the technical issues, she would still be bored.

Oh, and by the way–with all the hype about Ajax, you think it would be a little easier to discover how various vendors have implemented XMLHttpRequest, and that it can be called synchronously as well as asynchronously. I don’t really think it’s true that “the core Ajax technologies are mature, stable, and well understood.” But this is fodder for another essay.


Comments are closed.

%d bloggers like this: