2

Javascript 中,相等操作符两等号“==”与三等号 “===” 有什么区别?

 2 years ago
source link: https://foofish.net/JavaScript-equals.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

Javascript 中,相等操作符两等号“==”与三等号 “===” 有什么区别?

By 刘志军, 2021-09-21, 分类: javascript

JavaScript

Javascript 中,相等操作符两等号“==”与三等号 “===” 有什么区别?

1=="1"
true
1==="1"
false

看了这个例子你就明白, 两个等号的相等性判断,解释器会做自动类型转换,会将字符串“1”自动转换成数值1.现在已经被弃用,因为太迷惑了。而三等号操作符不会做类型转换,它是一种严格的相等操作符,只有值真正相同才会返回true

有问题可以扫描二维码和我交流

关注公众号「Python之禅」,回复「1024」免费获取Python资源

python之禅

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK