I have the following idiom:
if(typeof prop != 'null') {
}
I was under the impression that if prop is null, the != operator will convert the null object to the string ‘null’ for comparison?
In the above case, when prop is null, the expression is evaluated as true. Why does this idiom work for undefined? Isn’t undefined an object? Just as null is an object?
The type of a null object is still an “object”. If you alert(typeof prop) you’ll see it is an object.
You want to check for a null value.