javascript类型检测的坑

alert(typeof(NaN));

alert(typeof(Infinity));

alert(typeof(null) );

alert(typeof(undefined) );

alert((NaN==NaN) );

alert( (NaN!=NaN) );

alert((NaN>NaN) );

alert((null==undefined) );

alert((null>=undefined));

alert((null<=undefined) );

alert((null==null));

alert((null!=null) );

alert((null!=NaN) );

alert((null==NaN) );

alert((NaN==undefined) );

alert((parseInt("123abc")));

alert(("123abc"-0) );

alert((Infinity>10));

alert((Infinity>”abc”));

alert((Infinity==NaN));

alert((true==1) );

alert((new String(“abc”)==”abc”));

alert((new String(“abc”)===”abc”));

答案:
———————————————————–
alert(typeof(NaN)); //number

alert(typeof(Infinity));//number

alert(typeof(null) ); //object

alert(typeof(undefined) ); //undefined

alert((NaN==NaN) ); // false

alert( (NaN!=NaN) ); // true

alert((NaN>NaN) ); //false

alert((null==undefined) ); //true

alert((null>=undefined)); //false

alert((null<=undefined) ); //false

alert((null==null));//true

alert((null!=null) ); //false

alert((null!=NaN) ); //true

alert((null==NaN) );//fasle

alert((NaN==undefined) ); //false

alert((parseInt("123abc")));//123

alert(("123abc"-0) ); //NaN

alert((Infinity>10)); //true

alert((Infinity>”abc”)); //false

alert((Infinity==NaN));//false

alert((true==1) ); //true

alert((new String(“abc”)==”abc”)); //true

alert((new String(“abc”)===”abc”)); //false

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>