aboutsummaryrefslogtreecommitdiff
path: root/files/zh-cn/web/javascript/reference/operators/strict_equality/index.html
diff options
context:
space:
mode:
authorPeter Bengtsson <mail@peterbe.com>2020-12-08 14:40:17 -0500
committerPeter Bengtsson <mail@peterbe.com>2020-12-08 14:40:17 -0500
commit33058f2b292b3a581333bdfb21b8f671898c5060 (patch)
tree51c3e392513ec574331b2d3f85c394445ea803c6 /files/zh-cn/web/javascript/reference/operators/strict_equality/index.html
parent8b66d724f7caf0157093fb09cfec8fbd0c6ad50a (diff)
downloadtranslated-content-33058f2b292b3a581333bdfb21b8f671898c5060.tar.gz
translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.tar.bz2
translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.zip
initial commit
Diffstat (limited to 'files/zh-cn/web/javascript/reference/operators/strict_equality/index.html')
-rw-r--r--files/zh-cn/web/javascript/reference/operators/strict_equality/index.html101
1 files changed, 101 insertions, 0 deletions
diff --git a/files/zh-cn/web/javascript/reference/operators/strict_equality/index.html b/files/zh-cn/web/javascript/reference/operators/strict_equality/index.html
new file mode 100644
index 0000000000..125b67c168
--- /dev/null
+++ b/files/zh-cn/web/javascript/reference/operators/strict_equality/index.html
@@ -0,0 +1,101 @@
+---
+title: Strict equality (===)
+slug: Web/JavaScript/Reference/Operators/Strict_equality
+translation_of: Web/JavaScript/Reference/Operators/Strict_equality
+---
+<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 notranslate">x === y</pre>
+
+<h2 id="描述">描述</h2>
+
+<p>全等运算符(<code>===</code>和 <code>!==</code>)使用<a class="external external-icon" href="http://www.ecma-international.org/ecma-262/5.1/#sec-11.9.6" rel="noopener">全等比较算法</a>来比较两个操作数。</p>
+
+<ul>
+ <li>如果操作数的类型不同,则返回 <code>false</code>。</li>
+ <li>如果两个操作数都是对象,只有当它们指向同一个对象时才返回 <code>true</code>。</li>
+ <li>如果两个操作数都为 <code>null</code>,或者两个操作数都为 <code>undefined</code>,返回 <code>true</code>。</li>
+ <li>如果两个操作数有任意一个为 <code>NaN</code>,返回 <code>false</code>。</li>
+ <li>否则,比较两个操作数的值:
+ <ul>
+ <li>数字类型必须拥有相同的数值。<code>+0</code> 和 <code>-0</code> 会被认为是相同的值。</li>
+ <li>字符串类型必须拥有相同顺序的相同字符。</li>
+ <li>布尔运算符必须同时为 <code>true</code> 或同时为 <code>false</code>。</li>
+ </ul>
+ </li>
+</ul>
+
+<p>全等运算符与<a href="/zh-CN/docs/Web/JavaScript/Reference/Operators/Equality">相等运算符</a>(<code>==</code>)最显著的区别是,如果操作数的类型不同,<code>== </code>运算符会在比较之前尝试将它们转换为相同的类型。</p>
+
+<h2 id="例子">例子</h2>
+
+<h3 id="比较相同类型的操作数">比较相同类型的操作数</h3>
+
+<pre class="brush: js notranslate">console.log("hello" === "hello"); // true
+console.log("hello" === "hola"); // false
+
+console.log(3 === 3); // true
+console.log(3 === 4); // false
+
+console.log(true === true); // true
+console.log(true === false); // false
+
+console.log(null === null); // true</pre>
+
+<h3 id="比较不同类型的操作数">比较不同类型的操作数</h3>
+
+<pre class="brush: js notranslate">console.log("3" === 3); // false
+
+console.log(true === 1); // false
+
+console.log(null === undefined); // false</pre>
+
+<h3 id="比较对象">比较对象</h3>
+
+<pre class="brush: js notranslate">const object1 = {
+ name: "hello"
+}
+
+const object2 = {
+ name: "hello"
+}
+
+console.log(object1 === object2); // false
+console.log(object1 === object1); // true</pre>
+
+<h2 id="Specifications">Specifications</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_equality")}}</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_inequality">Strict inequality operator</a></li>
+</ul>