·您当前的位置:首页 > 技术教程 > JavaScript >

[js]说说js中的“==”与布尔值

时间:2016-09-01 10:50酷播
[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

热门文章推荐

请稍候...

保利威视云平台-轻松实现点播直播视频应用

酷播云数据统计分析跨平台播放器