Skip to content
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

[] == ![] 输出什么? #1

Open
sihai00 opened this issue Jul 18, 2019 · 0 comments
Open

[] == ![] 输出什么? #1

sihai00 opened this issue Jul 18, 2019 · 0 comments
Assignees

Comments

@sihai00
Copy link
Owner

sihai00 commented Jul 18, 2019

注意点1:逻辑非

  • !对象:false
  • !空字符串:true
  • !非空字符串:false
  • !数值0:true
  • !任务非0数值(包括Infinity):false
  • !null:true
  • !NaN:true
  • !undefined:true

注意点2:隐式转换

  • 如果有布尔值,将其转换为数值
  • 如果有字符串和数值,将字符串转换为数值
  • 如果有对象,先调用valueOf比较,如果还是对象或者数组,调用toString
[] == ![]

// !比==的优先级高,先执行!
[] == false

// 当比较中有布尔值时,优先把布尔值转化为数值
[] == 0

// 当比较中是对象,另一个是数值或字符串,把对象转换成基础类型的值再比较(valueOf 和 toString)
'' == 0

// 当字符串和数值对比时,把字符串转为数值进行对比
0 == 0         

// 结果:true
@sihai00 sihai00 self-assigned this Jul 18, 2019
@sihai00 sihai00 added bug and removed bug labels Jul 18, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant