What do we mean by undefined though?
Undefined is also the default type that will be returned when we're testing for unresolvable references (loosely speaking undeclared variables).
Now this is simple enough, but there are however a few caveats you need to be aware of.
Ideally this would be good enough, but lets have a quick look if it holds up against the aforementioned caveats.
In some browsers or rather pre ECMAScript 5 implementations, undefined can be assigned to like a writeable property, thereby making it very fickle and untrustworthy.
This is something that will phase out with time, but unfortunately we still need to cater for this possibility (unless you're evergreen browser assuming - debate for another day).
Equality wise null is equal to undefined, which means that if you were to use the equality instead of the identity operator on a null declared variable, the undefined statement would evaluate to true.
The fundamental difference is the types itself, null (weirdly enough) is an object, where undefined is a type.
If you're only interested in supporting evergreen browsers (or unconcerned about undefined being reassigned) and if unresolvable references won't be an issue for your specific context then the W3schools snippet will be sufficient.
But if you're looking for a more robust solution, something like the IIFE approach could be used; the most robust way to test for undefined variables however is by checking the type of the variable, this will also cater for unresolvable reference issues.