!= null
is false for undefined
, it basically means x !== null && x !== undefined
. !=
does type coercion, and one of the effects of that is that it treats null
and undefined
as equivalent (null == undefined
is true).
So unless you want that, some people recommend not using !=
with null
(or undefined
).
And you're quite right that the code defends against two (well actually three) possibilities:
Nothing was passed for the argument at all.
null
was passed.
undefined
was passed.
But the comment says it's a bad way to test whether an argument was passed, and it is: Because it doesn't catch passing null
or undefined
. (Passing in null
and not passing in anything are different cases.) That doesn't necessarily mean it's a bad way to check the argument for a specific function.