Javascript逻辑“!==”运营商? [英] Javascript logical "!==" operator?

查看:101
本文介绍了Javascript逻辑“!==”运营商?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在重新开始进行Web开发,并且最近一直试图重新审视jscript的细微差别。我正在通过构建在Three.JS之上的THREEx扩展库的源代码,注意到这个函数

I am getting back into web development, and have been trying to go over the nuances of jscript recently. I was pouring through the source of the THREEx extension library built on top of Three.JS and noticed this function

THREEx.KeyboardState.prototype.pressed  = function(keyDesc)
{
    var keys    = keyDesc.split("+");
    for(var i = 0; i < keys.length; i++){
        var key     = keys[i];
        var pressed;
        if( THREEx.KeyboardState.MODIFIERS.indexOf( key ) !== -1 ){
            pressed = this.modifiers[key];
        }else if( Object.keys(THREEx.KeyboardState.ALIAS).indexOf( key ) != -1 ){
            pressed = this.keyCodes[ THREEx.KeyboardState.ALIAS[key] ];
        }else {
            pressed = this.keyCodes[key.toUpperCase().charCodeAt(0)];
        }
        if( !pressed)   return false;
    };
    return true;
}

我特别关注这一行:

if( THREEx.KeyboardState.MODIFIERS.indexOf( key ) !== -1 ){

我不熟悉这个!==运算符。我检查了w3schools,他们的逻辑运算符列表中没有包含这个。我不确定这是否拼写错误,浏览器只是将其视为!=或者它是否有其他含义。另外我想知道这实际上是一个逻辑运算符还是它是某种组合,比如! + ==?

I am not familiar with this !== operator. I checked w3schools and their logical operators list does not have this one included. I am not sure if this is misspelled and the browsers simply count it as != or if it has some other meaning. Also I was wondering whether this is actually a single logical operator or whether it is some kind of combination, like ! + ==?

推荐答案

你可以找到 === !== 其他几种动态类型语言的运算符也是如此。它总是意味着这两个值不仅通过它们的隐含值进行比较(即,可以转换其中一个或两个值以使它们具有可比性),还可以通过它们的原始类型进行比较。

You can find === and !== operators in several other dynamically-typed languages as well. It always means that the two values are not only compared by their "implied" value (i.e. either or both values might get converted to make them comparable), but also by their original type.

这基本上意味着如果 0 ==0返回true, 0 ===0将返回false,因为您正在比较数字和字符串。同样,当 0!=0返回false时, 0!==0返回true。

That basically means that if 0 == "0" returns true, 0 === "0" will return false because you are comparing a number and a string. Similarly, while 0 != "0" returns false, 0 !== "0" returns true.

这篇关于Javascript逻辑“!==”运营商?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆