Hacker News new | past | comments | ask | show | jobs | submit login
The difference between undefined and null in Javascript (saladwithsteve.com)
16 points by rantfoil on April 14, 2008 | hide | past | favorite | 2 comments



Nice clear up, but still wrong/bad... The author swaps one problem for another.

When people write

if (foo==null)

OR

if (!foo)

To check if something exists, they really meant to write

if ((typeof foo)=='undefined')

You can't check for a property existing by coercing into a boolean. That's horrible. What if it does exist, and holds a boolean.


I like the way Lua does it, where "null" and "undefined" are the same concept, and represented by nil. I don't know if that could be done in Javascript though due to the difference between variable access and property access.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: