当前位置:网站首页>JS: why [] = =! [] return true?
JS: why [] = =! [] return true?
2022-07-24 06:37:00 【Slugs are not alone】
Let's start with a piece of code
[] == ![] //true
'' == ![] //true
1 == ![] //false
0 == ![] //true
![] == false //true
Is it a little cloudy ? Next, look at a picture :

In this algorithm , and [] == ![] What matches is the condition 7, So call [] == ToNumber(false) Compare . stay 9.3 In the festival ,ToNumber(false) be equal to 0, So the comparison becomes [] == 0 .
Here because [] It's the object , The comparison process takes branches 9, In accordance with the ToPrimitive([]) == 0 Compare .ToPrimitive Call by default toString Methodical ( In accordance with the 8.2.8), therefore ToPrimitice([]) Equal to an empty string .
result ,[] == ![] The comparison of finally fell to ‘’==false On , according to 11.9.3 The definitions in will be based on branches 5 Compare ToNumber(’’)==0 ,ToNumber(’’) In accordance with the 9.3.1 be equal to 0, So the result is true.
边栏推荐
猜你喜欢
随机推荐
mysql 忘记退出直接关闭窗口现在要删除整个文件夹如何删除
NFS共享服务及实验
DNS domain name resolution service
awk的使用
实验:磁盘配额操作
Custom MVC 1.0
[226] instructions for Wireshark parameters
PXE technology network installation
Restful API introduction
Flex layout
Ia class summary (2)
Crud of MySQL
Promise
A batch of interview questions and answers_ 20180403 latest arrangement
在IDEA里斗个地主不过分吧!
[222] memory overflow and location
三分钟记住20道性能测试经典面试题
Leetcode does not add, subtract, multiply, divide, and calculate the number of 1 in binary
Server hardware and RAID configuration practice
Quickly and simply set up FTP server, and achieve public network access through intranet [no need for public IP]









