aboutsummaryrefslogtreecommitdiff
path: root/files/zh-cn/web/javascript/reference/operators/strict_inequality/index.html
blob: 26efd1748f1e9e2a59682670ad68b8a0858e84c7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
---
title: 严格不相等 (!==)
slug: Web/JavaScript/Reference/Operators/Strict_inequality
translation_of: Web/JavaScript/Reference/Operators/Strict_inequality
---
<div>{{jsSidebar("Operators")}}</div>

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

<div>{{EmbedInteractiveExample("pages/js/expressions-strict-equality.html")}}</div>

<div class="hidden">The source for this interactive example is stored in a GitHub repository. If you'd like to contribute to the interactive examples project, please clone <a href="https://github.com/mdn/interactive-examples">https://github.com/mdn/interactive-examples</a> and send us a pull request.</div>

<h2 id="语法">语法</h2>

<pre class="syntaxbox">x !== y</pre>

<h2 id="描述">描述</h2>

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

<pre class="brush: js">x !== y

!(x === y)</pre>

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

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

<pre class="brush: js">3 !== "3"; // true</pre>

<h2 id="示例">示例</h2>

<h3 id="比较相同类型的对象">比较相同类型的对象</h3>

<pre class="brush: js">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</pre>

<h3 id="比较不同类型的对象">比较不同类型的对象</h3>

<pre class="brush: js">console.log("3" !== 3);           // true

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

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

<h3 id="比较Object对象">比较Object对象</h3>

<pre class="brush: js">const object1 = {
  name: "hello"
}

const object2 = {
  name: "hello"
}

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

<h2 id="规范">规范</h2>

<table class="standard-table">
 <thead>
  <tr>
   <th scope="col">Specification</th>
  </tr>
 </thead>
 <tbody>
  <tr>
   <td>{{SpecName('ESDraft', '#sec-equality-operators', 'Equality operators')}}</td>
  </tr>
 </tbody>
</table>

<h2 id="浏览器兼容">浏览器兼容</h2>



<p>{{Compat("javascript.operators.strict_inequality")}}</p>

<h2 id="See_also">See also</h2>

<ul>
 <li><a href="/en-US/docs/Web/JavaScript/Reference/Operators/Equality">Equality operator</a></li>
 <li><a href="/en-US/docs/Web/JavaScript/Reference/Operators/Inequality">Inequality operator</a></li>
 <li><a href="/en-US/docs/Web/JavaScript/Reference/Operators/Strict_equality">Strict equality operator</a></li>
</ul>