严格不相等 (!==)

翻译不完整。 请帮助我们翻译这篇文章!

严格不等式操作符(!==)检查它的两个对象是否不相等,返回一个布尔结果。与不等式运算符不同,严格不等式运算符总是认为不同类型的对象是不同的。

语法

x !== y

描述

严格不等式运算符检查其对象是否不相等。它是严格相等运算符的否定,因此下面两行总是会给出相同的结果:

x !== y

!(x === y)

有关比较算法的详细信息,请参阅严格相等运算符的页面。

与严格相等运算符一样,严格不等运算符始终认为不同类型的对象是不同的:

3 !== "3"; // true

示例

比较相同类型的对象

console.log("hello" !== "hello");   // false
console.log("hello" !== "hola");    // true

console.log(3 !== 3);               // false
console.log(3 !== 4);               // true

console.log(true !== true);         // false
console.log(true !== false);        // true

console.log(null !== null);         // false

比较不同类型的对象

console.log("3" !== 3);           // true

console.log(true !== 1);          // true

console.log(null !== undefined);  // true

比较Object对象

const object1 = {
  name: "hello"
}

const object2 = {
  name: "hello"
}

console.log(object1 !== object2);  // true
console.log(object1 !== object1);  // false

规范

Specification
ECMAScript (ECMA-262)
Equality operators

浏览器兼容

Update compatibility data on GitHub
DesktopMobileServer
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidFirefox for AndroidOpera for AndroidSafari on iOSSamsung InternetNode.js
Strict inequality (a !== b)Chrome Full support 1Edge Full support 12Firefox Full support 1IE Full support 4Opera Full support 4Safari Full support 1WebView Android Full support 1Chrome Android Full support 18Firefox Android Full support 4Opera Android Full support 10.1Safari iOS Full support 1Samsung Internet Android Full support 1.0nodejs Full support 0.1.100

Legend

Full support  
Full support

See also