[js]说说js中的“==”与布尔值
[js]说说js中的“==”与布尔值,关于"=="的比较规则:
1. Comparing numbers and strings will always convert the strings to numbers.
number类型与string类型比较,string会转换为number类型。如:2=="2" true
2. null and undefined will always equal each other.
null类型与undefined类型比较始终相等。如:var a = null,b; 则 a==b 为true。
3. Comparing booleans to any other type will always cause the booleans to be converted to numbers.
布尔类型与其他任何类型进行比较,布尔类型将会转换为number类型。如:var a = 0, b = false;则a==b为true
4. Comparing numbers or strings to objects will always cause the numbers or strings to be converted to objects.
number类型或者string类型与object类型进行比较,number或者string类型都会转换为object类型。如:var a = 0, b = {};则a==b为false
热门文章推荐
- [JS]window.location获取url各项参数详解
- [JS]jQuery,javascript获得网页的高度和宽度
- [JS]视频弹窗视频弹出层videoLightBox(含三种播放器的用法)
- [JS]JS提交中文encodeURI两次转码
- [JS]js版方面encodeURI转码和decodeURI解码的用法实例
- [JS]js取当前机子的时间戳实例
- [JS]AES加密(基于crypto-js)PHP后端解密
- [JS]data:image/png;base64写法的用途及说明