javascript中的!==是什么?
What is !== in javascript?
代码用于验证图像或单元格选择。我的问题是
在下列函数中使用!==做什么:function checkSelected() {
var cellList,
selectedCell,
imgList,
selectedImg,
i
cellList = document.getElementById("imgTable")
cellList = cellList.getElementsByTagName("td")
imgList = document.getElementById("b_list")
imgList = imgList.getElementsByTagName("img")
if (cellList[0].style.border.indexOf("7px outset") !== -1) { selectedCell = cellList[0] }
if (selectedCell === undefined || selectedImg === undefined) { return }
selectedCell.style.backgroundImage = "url(" + selectedImg.src + ")"
selectedCell.firstChild.style.visibility = "hidden"
selectedCell.style.border = "1px solid"
selectedImg.style.border = "1px solid"
}
!==
是一个更严格的不等式,它不会对操作数执行任何类型强制转换,而!=
会执行类型强制转换。
因此,如果操作数不相等且/或类型不同,!==
将返回true。
相反,如果操作数相等,!=
返回true。如果操作数不是同一类型,JavaScript将尝试将两个操作数转换为适合比较的形式。如果操作数是对象,那么JavaScript将比较它们的引用(内存地址)。最好的示例如下:
"3" != 3; // returns false because JavaScript will perform
// type coercion and compare the values
"3" !== 3; // returns true because the first operand is a
// string whereas the second is an integer. Since
// they are of different types, they are not equal.
有关更多信息,请查看MDN上的比较运算符
它的意思是"不严格等于",而!=
的意思是"不等于"。
检查相等性的方法有两种:==
和===
,它们分别是"相等"answers"严格相等"。要查看确切的差异,请查看此表。
!=
和!==
只是这些操作的对应的负运算。例如a !== b
和!(a === b)
是一样的
相关文章:
- 确定var是否是javascript中的elementFinder对象的方法是什么
- JavaScript中的数组是什么类型的列表
- 在JavaScript中调用array()作为构造函数时,返回的是什么类型的数组
- 什么是反应中的事件池
- 什么是 react 中的父子耦合以及它与上下文的关系
- 什么是jQuery中的工厂函数
- 什么是javascript中的哈希?如何对数组使用哈希
- FileWriter在javascript中究竟是什么工作的
- 什么是JavaScript中的实例
- 这在 Java 脚本中是什么类型的对象?以及如何将这种元素添加到此对象中
- 什么是 JavaScript 中的对象 #
- 我什么时候应该更喜欢克隆而不是 javascript 中的引用
- 什么是JS中的“>>>”运算符
- 什么是 ES6 中的动态导出
- 什么是 JavaScript 中的对象
- 什么是 javascript 中的 [[param1, param2 .. ]] 结构
- 什么是函数中的“返回(var > -1)”
- Javascript 什么是参数中的“索引”
- 什么是URL中的回调
- 什么是 JavaScript 中的 [] + []