I wasn't sure if this was implementation dependent, so I checked in
the browsers I have installed.
undefined returns equal to ('==') the undefined keyword,
values that have not been defined, and null.
All other values are not == undefined.
The only change the equivilence ('===') operator enforces is
that it distinguishes null values from undefined.
If you do NOT want to treat null as if it were undefined, use '!==',
otherwise use '!='.
Code:
var non=[0, false, NaN ,'',null, undefined];
var tx= '0,false,NaN,"",null,undefined (keyword),'.split(/,/);
var A=['Expressions with undefined',''], i=0, str='';
while(i< 7){
if(tx[i]===undefined) tx[i]='~Really undefined~';
A.push('('+tx[i]+ ' != undefined) returns '+ (non[i] != undefined));
if(non[i] == undefined){
A.push('and ('+tx[i]+ ' !== undefined) returns '+ (non[i] !== undefined));
}
A.push('');
i++;
}
alert(A.join('\n'))
Bookmarks