typeof & Nan & ==

本文介绍了JavaScript中的基本数据类型,包括数字、字符串等,并详细解释了如何正确判断这些类型的值。此外,还探讨了不同类型的值进行比较时的陷阱及推荐做法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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:

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值