当前位置:网站首页>JS中的==和===的区别(详解)
JS中的==和===的区别(详解)
2022-06-25 15:32:00 【Fairy-KunKun】
简单来说:==代表相同,===代表严格相同,为啥这么说呢
这么理解:当进行双等号比较时候: 先检查两个操作数数据类型,如果相同,则进行===比较,如果不同,则愿意为你进行一次类型转换,转换成相同类型后再进行比较,而===比较时,如果类型不同,直接就是false。
操作数1 == 操作数2, 操作数1 === 操作数2
比较过程:
双等号==:
(1)如果两个值类型相同,再进行三个等号(===)的比较
(2)如果两个值类型不同,也有可能相等,需根据以下规则进行类型转换在比较:
1)如果一个是null,一个是undefined,那么相等
2)如果一个是字符串,一个是数值,把字符串转换成数值之后再进行比较
三等号===:
(1)如果类型不同,就一定不相等
(2)如果两个都是数值,并且是同一个值,那么相等;如果其中至少一个是NaN,那么不相等。(判断一个值是否是NaN,只能使用isNaN()来判断)
(3)如果两个都是字符串,每个位置的字符都一样,那么相等,否则不相等。
(4)如果两个值都是true,或是false,那么相等
(5)如果两个值都引用同一个对象或是函数,那么相等,否则不相等
(6)如果两个值都是null,或是undefined,那么相等
边栏推荐
- 基于深度Q学习的雅达利打砖块游戏博弈
- Is it safe to open an account for new bonds? What preparations are needed
- Sword finger offer 06 Print linked list from end to end
- 在打新债开户证券安全吗,需要什么准备
- How to package rpm
- Leetcode121 timing of buying and selling stocks
- JVM memory region details
- google_ Breakpad crash detection
- Download and installation tutorial of consumer
- Software packaging and deployment
猜你喜欢

Why do I need message idempotence?

Fishing detection software

Day01: learning notes

Sword finger offer 04 Find in 2D array

Brief object memory layout

Esp8266 building smart home system

QT pattern prompt box implementation

免费送书啦!火遍全网的AI给老照片上色,这里有一份详细教程!
How to convert a recorded DOM to a video file

MySQL performance optimization - index optimization
随机推荐
通过客户经理的开户链接开股票账户安全吗?
Esp8266 building smart home system
iconv_ Open returns error code 22
Sword finger offer 06 Print linked list from end to end
GDB debugging
04. binary tree
Sword finger offer 03 Duplicate number in array
Sword finger offer II 091 Paint the house
semget No space left on device
Is it safe to open a stock account through the account opening link given by the account manager? I want to open an account
MySQL修改字段語句
Why do I need message idempotence?
For the first time in Chinese universities! Unique in the world! Tongji students win international awards
剑指 Offer 07. 重建二叉树
Boost listening port server
Sword finger offer 04 Find in 2D array
MySQL transaction characteristics and implementation principle
Install Kali extension 1: (kali resolution problem)
Arthas source code learning-1
MySQL performance optimization - index optimization