Checking for undefined: === versus typeof versus falsiness http://ift.tt/15pSGBZ...

Please Visit: http://ift.tt/1ajReyV



Checking for undefined: === versus typeof versus falsiness

http://ift.tt/15pSGBZ

if (x === undefined) ...

if (typeof x === 'undefined') ...

if (!x) ...

The usual caveat applies: The condition of the above if statement will also be true for: null, false, -0, +0, NaN, "".



There are several ways of checking whether a variable has the value undefined. This blog post explains the differences. Checking via === Using strict equality [1] is the canonical way of checking for undefined: if (x === undefined) ... Changing undefined. undefined is a property of the global ...







from Public RSS-Feed of Jeffery yuan. Created with the PIXELMECHANICS 'GPlusRSS-Webtool' at http://gplusrss.com http://ift.tt/1ggWJRs

via LifeLong Community

No comments:

Post a Comment