什么是!==用javascript?

什么是!==用javascript?,javascript,Javascript,该代码用于验证图像或单元格选择。我的问题是 什么是!==用于以下功能中: function checkSelected() { var cellList, selectedCell, imgList, selectedImg, i cellList = document.getElementById("imgTable") cellList = cellList.getElementsByTagName("

该代码用于验证图像或单元格选择。我的问题是 什么是!==用于以下功能中:

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"
}
它的意思是“不完全等于”,而不是
=表示“不等于”

检查是否相等有两种方法:
=
=
,分别是“相等”和“严格相等”。要查看确切的区别,请查看


=
==只是这些操作的相应否定。例如
a!==b
相同!(a==b)

==相比,code>是一个更严格的不等式,它不会对操作数执行任何类型强制=,它执行类型强制

所以
==将返回true

相比之下,
=
"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的内容。

我明白了,但是,它在IF语句中的用途是什么?它是否用于验证Null?我在您共享的代码中看到它的唯一位置是
.indexOf(“7px开始”)!==-1
。这意味着“如果
.indexOf
的值不是
-1
(使用该参数调用),则给出
true
。我们知道
。字符串上的indexOf
将具有类型编号,因此我们可以愉快地使用
!=-1
,因为
-1
也是一个数字。根据Paul S所说的,您可能感兴趣的是
-1==”-1“
为真,而
-1==”-1“
为假。