Author Topic: Stupid JavaScript (grrrr)  (Read 2423 times)

hans

  • Guitar Addict
  • Jackass In Charge
  • Posts: 3523
  • Karma: +46/-18
Stupid JavaScript (grrrr)
« on: February 06, 2007, 04:27:09 PM »
OK, so I code quite a bit of VXML for work and within the VXML you can use JavaScript to do some useful things. Well, today I racked my brain because I'm not a JavaScript guru and tried to get away with being clever (not horribly mind you).
So in part of my code I wanted to bypass something by setting a value to '' (empty string. Now comes the fun part, the value sometimes can be 0 (the number zero not the string). And like every other flippin' language I code val != '' to make sure I'm not going to bypass. Well, JavaScript thinks 0 == '', which is obviously intuitive. I mean why would anyone think those don't match. I did find a blog about the gotcha with an explanation but grrr.

Don't even get me started on null and undefined.
This signature intentionally left blank.