Following your own advice
June 2nd, 2009
Well I have been pulling my hair out trying to debug a Javascript issue, and it turns out that not only do I know the solution, but I JUST blogged about it! You see, in Javascript, an empty string will return false in an if statement, so:
val=”";
if (val){ …
will return false. Although it shouldn’t, because it IS technically a value (the value of nothing). SO, using a !== fixes this, as earlier in the code I explicitly set it to false, then change it to a value if I need. Long story short,
if (val !== false){ …..
is what I should have done in the first place!