4 ms·
This is a dangerous rule; if you put this rule in the hands of a programmer who is not used to Javascript and doesn't really understand the type system, you can
by chavesn 13y ago
This is a dangerous rule; if you put this rule in the hands of a programmer who is not used to Javascript and doesn't really understand the type system, you can just as easily run into problems.
This is because you require the programmer to always understand the output (and defaults) of every call made. Sometimes it's undefined. Sometimes it's null. Sometimes it's empty string. This takes experience.
Example, the default for getAttribute is null, but an undefined property is undefined:
document.body.getAttribute("test"); // null
document.body.test; // undefined
Except if it's a special property, then getAttribute might still be null, but the property empty string:
var input = document.createElement("input");
input.getAttribute("value"); // null
input.value; // ""
Remember, "" !== null and null !== undefined.