3 ms·
The difference between undefined and null in Javascript
- axod 19y agoNice 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.
- LogicHoleFlaw 19y agoI 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.