Don't confuse undefined and null as they are not the same thing.
null:
The value null represents the intentional absence of any object value. It is one of JavaScript's primitive values.
undefined:
A variable that has not been assigned a value is of type undefined. A method or statement also returns undefined if the variable that is being evaluated does not have an assigned value. A function returns undefined if a value was not returned.
If the variable consists of a value that is neither null
nor undefined
, then no there is no difference in your condition.
const value = 3;
console.log(value !== undefined) //true
console.log(value !== null) //true
However, a better way of testing if the variable is null
or undefined
is to use !
negation as the value null
or undefined
will be resolved to true.
const undefinedValue = undefined;
const nullValue = null;
console.log(!undefinedValue);
console.log(!nullValue);
Here are some examples of it.
var someVariable = undefined;
console.log(someVariable !== undefined, "; undefined !== undefined");
console.log(someVariable !== null, "; undefined !== null");
var someVariable = null;
console.log(someVariable !== undefined, "; null !== undefined");
console.log(someVariable !== null, "; null !== null");
var someVariable = undefined;
console.log(!someVariable);
var someVariable = null;
console.log(!someVariable);