Monday, January 26, 2015; 2:51:14 PM Eastern
JavaScript type coercion fail
- If you're not into JavaScript, please ignore. :-)
- I just spent an hour learning that this doesn't work in JavaScript:
var x = 12; alert (x.toLowerCase ());
- Instead you have to say:
var x = 12; alert (x.toString ().toLowerCase ());
- #### Why?
- This seems counter to the philosophy of JavaScript, which strives to make sense of everything, no matter how convoluted. In this case it's fairly obvious what I wanted to do.
- Only in very special circumstances in the code I'm working on is x a number. And when it is, converting it to lowercase, which should be a no-op, fails.
- It doesn't help that Chrome's debugger is totally borked, and I had to resort to println debugging, which I used to do before there were source debuggers.
- #### Can't fix
- BTW, I would never advocate changing the behavior. Too deep, huge breakage potential.