Late to the story but I think some details are overlooked?
if you use
if (uemail !== undefined) {
//some function
}
You are, technically, comparing variable uemail
with variable undefined
and, as the latter is not instantiated, it will give both type and value of 'undefined' purely by default, hence the comparison returns true.
But it overlooks the potential that a variable by the name of undefined
may actually exist -however unlikely- and would therefore then not be of type undefined.
In that case, the comparison will return false.
To be correct one would have to declare a constant of type undefined for example:
const _undefined: undefined
and then test by:
if (uemail === _undefined) {
//some function
}
This test will return true
as uemail
now equals both value & type of _undefined
as _undefined
is now properly declared to be of type undefined.
Another way would be
if (typeof(uemail) === 'undefined') {
//some function
}
In which case the boolean return is based on comparing the two strings on either end of the comparison. This is, from a technical point of view, NOT testing for undefined, although it achieves the same result.