I think both, depending on what you are testing? If this property, I would always use x === undefined , as it is more understandable (and seems to be faster).
As others have said, x === undefined will not work if x is not declared. Personally, I think this is an even better reason to use it, since I usually should not check if a variable is declared at all - this is usually a sign of an encoding error.
I saw a lot of other version for testing arguments - f = function(x) {if (typeof x == 'undefined') …} - if I have code to check the code like this, I will tell them to change it. We know that a variable is declared, and creating the habit of writing it in this way increases the likelihood that you will spend time trying to chase typo errors.
The main exception is when you try to check if a component or library is loaded or initialized correctly. if (typeof jQuery == 'undefined') … makes sense. But in the medium term, all this should become a module in any case, and in this case, a type test should, in my opinion, be phased, as harmful.
(In addition, I personally prefer if (window.jQuery === undefined) for this case. However, it is not portable for isomorphic code.)
source share