严格不相等(!==)
Baseline Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.
严格不相等运算符(!==
)检查它的两个对象是否不相等,返回一个布尔结果。与不相等运算符不同,严格不相等运算符总是认为不同类型的对象是不同的。
尝试一下
console.log(1 !== 1);
// Expected output: false
console.log("hello" !== "hello");
// Expected output: false
console.log("1" !== 1);
// Expected output: true
console.log(0 !== false);
// Expected output: true
语法
js
x !== y
描述
示例
比较相同类型的对象
js
"hello" !== "hello"; // false
"hello" !== "hola"; // true
3 !== 3; // false
3 !== 4; // true
true !== true; // false
true !== false; // true
null !== null; // false
比较不同类型的操作数
js
"3" !== 3; // true
true !== 1; // true
null !== undefined; // true
比较对象
js
const object1 = {
key: "value",
};
const object2 = {
key: "value",
};
console.log(object1 !== object2); // true
console.log(object1 !== object1); // false
规范
Specification |
---|
ECMAScript® 2025 Language Specification # sec-equality-operators |
浏览器兼容性
Report problems with this compatibility data on GitHubdesktop | mobile | server | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Strict inequality ( a !== b ) |
Legend
Tip: you can click/tap on a cell for more information.
- Full support
- Full support
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.