typeof & Nan & ==

来源:互联网 发布:汉诺塔递归python语言 编辑:程序博客网 时间:2024/06/05 03:03

readed 'JavaScript:the good part',and Add some note here :

 

1)Several Types in JS:numbers,strings,booleans,null,undefined,objects.

numbers&strings have methods,but the diff is objects are keyed collections . arrays,functions,regular expressions are objects.we can dig into it by typeof operator.

2)'Nan' and ' =='

 

JS has two sets of equality '==='and !===,and their evil twins == and !=.

 

IF the two operands are of the same type and have the same value,then === produces true and !== produces false;

the EVIL twins do right thing when the operands are of the same type,BUT IF THEY ARE DIFFERENT TYPE ,THEY ATTEMPT TO COERCE THE VALUE,unforunately,the rules are complicated,SO DO NOT USE IT IF POSSIBLE

 

 

By the way ,the operator NaN is the evil part too, so if you want to check the number,use this: