当前位置:网站首页>js基础及常考面试题之 [] == ![]结果为true, []==[]结果为false 详解
js基础及常考面试题之 [] == ![]结果为true, []==[]结果为false 详解
2022-06-10 19:32:00 【Rulyc】
[] == ![]
第一步: !优先级高于==,故而先计算 ![]; 所有的对象都是true,所以 []为true; 所以!true就为false
即: [] == false
第二步:如果有一个操作数为布尔类型,则将布尔类型转化为数值类型
即: [] == 0
第三步: 将另一个操作类型转化为数值类型,[]转化为数值类型为0
即 0 == 0
故: 结果为 true
[] == []
左右两边类型相同,都是数组类型;但,数组或者对象在比较的时候,是比较他们的引用地址
如: var a = []; var b=a; console.log(a==b) -----------true
原因: a与b都是引用的同一个地址,a与b的随意一个改变,都会引起地址变化.
如: var a= [], b = [] ; console.log(a==b)--------------false
原因: a与b的地址不同
形象例子: 就好比[] 是一笼包子
第一种场景: a买了一笼包子, 并把这一笼子共享给了b, a与b也就共同拥有这一笼包子,谁吃都会减少
第二种场景: a买了一笼子,b也买了一笼子, a吃一个包子,b的那笼包子里并不会减少。
故而: 结果为false
附上==, === 的流程图
在 JS 中类型转换只有三种情况,分别是:
转换为布尔值
转换为数字
转换为字符串
js中数值转化表格:
边栏推荐
- 「Bug」问题分析 RuntimeError:which is output 0 of ReluBackward0
- MySQL backup and manual execution of shell scripts are OK, and crontab scheduled execution fails
- P5723 【深基4.例13】质数口袋
- vulnhub-The Planets: Earth
- 【legendre】多项式
- localhost和127.0.0.1的区别?
- CVPR 2022 Tsinghua University proposed unsupervised domain generalization (UDG)
- RuntimeError: Attempting to deserialize object on CUDA device 1 but torch.cuda.device_count() is 1.
- On the development trend of enterprise storage: cold thoughts on open source storage
- [technical fragment] implementation of renaming and filtering duplicate name files with suffixes
猜你喜欢

AttributeError: module ‘collections‘ has no attribute ‘MutableMapping‘
![[observation] shengteng Zhixing: scene driven, innovation first, press the](/img/53/29f5fd8b869087bafbe74849329c84.jpg)
[observation] shengteng Zhixing: scene driven, innovation first, press the "acceleration key" for Intelligent Transportation

Key points of lldp protocol preparation

Analysis on rendering principle of mobile terminal

C语言 浮点数 储存形式

Knowledge map / relationship visualization

LLDP协议编写要点

PDU session flow

Solution to the problem that JLINK CDC UART driver cannot be installed normally under win7 system

First batch! Sinomenine has passed CWPP capability assessment and inspection of Xintong Institute
随机推荐
RT-Thread Smart Win10 64位下编译环境的搭建
Fs4100 lithium battery charging management IC input 12V to 8.4v charging IC
观点丨Play and Earn 会让加密游戏误入歧途
[FAQ] summary of common problems and solutions during the use of rest API interface of sports health service
Esp8266 system environment setup
Unity 分析内置地形(Terrain)的渲染并做一些有意思的事情
KP522201A采用 SOT23-6 封装的 4.5V 至 17V 输入、2A 输出、600kHz 同步降压转换器
用 Plotly 绘制了几张精湛的图表,美翻了!!
Fs4060a is a 4.2v/3a charging IC
Open the door of the hybrid cloud market, Lenovo xcloud's way to break the situation
老程序员说:别再直译这大千世界了,开发人员应该回归程序设计
安全隐患?意义有限?挡不住真煮迷你厨具火爆618
Basic instructions for ads and AXD
ResourceNotFoundException : Unable to find resource
Deploying static websites using OSS and CDN on Alibaba cloud international
canvas 高级功能(中)
深度学习调参经验和工具
Zabbix_监控ssh/crond服务-微信告警
Enhance the target method with surround notifications - extract notes
一个10年左右的老程序员说:简单CRUD功能进入无码开发时代1 之 增删改查接口信息