Home > Programming > Following your own advice

Following your own advice

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!

Chris Fontes Programming

  1. No comments yet.
  1. No trackbacks yet.

Powered by WP Hashcash