I see this throughout our codebase:
(function(undefined) {
var foo = {
dirtyRow: undefined,
dirtyCells: undefined,
...
clearDirty: function () {
this.dirtyRow = undefined;
this.dirtyCells = undefined;
}
}
})();
Can someone articulate for me what’s wrong with this? What should we be doing instead?
nullmakes more sense thanundefinedin this context, because you are defining the variables but are not yet assigning a value to them.However both
nullandundefinedare falsy values, so for the most part the behaviour will be the same.nullis a keyword though, whereasundefinedis not. Sonullwould be more “reliable”, even if you are using the argument to ensure thatundefinedis in fact undefined.