New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[js] 第67天 举例子说说你对js隐式类型转换的理解 #409
Comments
js中双等号比较的时候也会产生隐式类型转换,所以才推荐采用三个等号进行比较是否相等。另外比如 |
|
这个应该是11,不是2 |
其实这里面的坑实在是有点多,比如等于判断,大小判断,入参类型转换,运算时类型转换等等。 等于判断等于判断时,是会去先转为相同数据类型,再判断的。
大小判断也是要先转为相同数据类型再比较的,但有很多令人费解的地方。
所以这会造成下面这种结果:
再者,undefined、null 和 NaN 一直都很特别。
入参类型转换比如 Number 和 Math 相关的方法,都会进行数字化转化等。 运算时类型转换
|
js在做运算时,如果两边数据不一样,编译器会自动做一个数据转换再进行比较 转换规则
特殊点: 2.Boolean转换在以下几种情况下为false: 3.undefined与null的特殊情况 4.NaN与任何数据比较都是false,包括自己 // 六亲不认的步伐 |
|
应该是 console.log(1+ +'1') |
第67天 举例子说说你对js隐式类型转换的理解
The text was updated successfully, but these errors were encountered: