Movatterモバイル変換


[0]ホーム

URL:


  1. 面向开发者的 Web 技术
  2. JavaScript
  3. JavaScript 参考
  4. 表达式和运算符
  5. 严格不相等(!==)

此页面由社区从英文翻译而来。了解更多并加入 MDN Web Docs 社区。

View in EnglishAlways switch to English

严格不相等(!==)

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since ⁨2015年7月⁩.

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

尝试一下

console.log(1 !== 1);// Expected output: falseconsole.log("hello" !== "hello");// Expected output: falseconsole.log("1" !== 1);// Expected output: trueconsole.log(0 !== false);// Expected output: true

语法

js
x !== y

描述

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

js
x !== y;!(x === y);

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

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

js
3 !== "3"; // true

示例

比较相同类型的对象

js
"hello" !== "hello"; // false"hello" !== "hola"; // true3 !== 3; // false3 !== 4; // truetrue !== true; // falsetrue !== false; // truenull !== null; // false

比较不同类型的操作数

js
"3" !== 3; // truetrue !== 1; // truenull !== undefined; // true

比较对象

js
const object1 = {  key: "value",};const object2 = {  key: "value",};console.log(object1 !== object2); // trueconsole.log(object1 !== object1); // false

规范

Specification
ECMAScript® 2026 Language Specification
# sec-equality-operators

浏览器兼容性

参见

Help improve MDN

Learn how to contribute

This page was last modified on byMDN contributors.


[8]ページ先頭

©2009-2025 Movatter.jp