javascript - JavaScript中的三等号首先比较类型的值?
问题描述
三等分测量值和类型。但我想知道它首先比较值并返回 false 的顺序,反之亦然。
解决方案
它首先检查类型:
https://262.ecma-international.org/5.1/#sec-11.9.6
If Type(x) is different from Type(y), return false.
If Type(x) is Undefined, return true.
If Type(x) is Null, return true.
If Type(x) is Number, then
If x is NaN, return false.
If y is NaN, return false.
If x is the same Number value as y, return true.
If x is +0 and y is −0, return true.
If x is −0 and y is +0, return true.
Return false.
If Type(x) is String, then return true if x and y are exactly the same sequence of characters (same length and same characters in corresponding positions); otherwise, return false.
If Type(x) is Boolean, return true if x and y are both true or both false; otherwise, return false.
Return true if x and y refer to the same object. Otherwise, return false.
推荐阅读
- php - 在 php 的网格中显示上传的文件或图像
- c - Doxygen 如何处理枚举声明中的包含
- python-3.x - 如何在不等待响应的情况下使用 request.post() 方法
- java - 如何将 registerNetworkCallback 与 PendingIntent 一起使用?
- build - 我应该设置 src_uri 吗?
- php - 信息未提交到数据库
- ejs - VSCode 中的 .ejs 格式
- angular - 在嵌套的导入模块中导入 ReactiveFormsModule 会使应用程序崩溃
- git - 使用 .gitmodules 文件构建多个存储库的 TFS 无法正常工作
- batch-file - 从批处理文件窗口在程序中打开文件