Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
3.0k views
in Technique[技术] by (71.8m points)

怎样理解对象转换问题?

console.log({}==0) //false
console.log([]==0) //true

这个是什么原理,到底调用了什么方法?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

这里 toString 了。

[].toString() 是空字符串 ''(因为数组直接 toString 就相当于用逗号做 join),'' == 0 成立。

https://developer.mozilla.org...

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...