use "typeof foo === 'undefined'" to check for undefined.  It's not usually a problem, but due to js weirdness undefined can actually be instantiated as a variable and take on a different meaning, borking your equality tests.