blob: afb4a2d134ac268bfc1e8c162e2b8d5015087fdd (
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/Greater_than
translation_of: Web/JavaScript/Reference/Operators/Greater_than
---
<div>{{jsSidebar("Operators")}}</div>
<p>当左边操作数大于右边的时候,大于(<code>></code>) 运算符返回<code>true</code>,否则返回<code>false</code></p>
<div>{{EmbedInteractiveExample("pages/js/expressions-greater-than.html")}}</div>
<h2 id="语法">语法</h2>
<pre class="syntaxbox notranslate">x > y</pre>
<h2 id="描述">描述</h2>
<p>操作数之间按照 <a class="external external-icon" href="https://tc39.es/ecma262/#sec-abstract-relational-comparison" rel="noopener">Abstract Relational Comparison</a> 算法进行比较。进一步了解该算法,请参考 <a href="/en-US/docs/Web/JavaScript/Reference/Operators/Less_than">小于</a> 运算符的相关文档.</p>
<h2 id="例子">例子</h2>
<h3 id="字符串的比较">字符串的比较</h3>
<pre class="brush: js notranslate">console.log("a" > "b"); // false
console.log("a" > "a"); // false
console.log("a" > "3"); // true</pre>
<h3 id="字符串和数字的比较">字符串和数字的比较</h3>
<pre class="brush: js notranslate">console.log("5" > 3); // true
console.log("3" > 3); // false
console.log("3" > 5); // false
console.log("hello" > 5); // false
console.log(5 > "hello"); // false
console.log("5" > 3n); // true
console.log("3" > 5n); // false</pre>
<h3 id="数字间的比较">数字间的比较</h3>
<pre class="brush: js notranslate">console.log(5 > 3); // true
console.log(3 > 3); // false
console.log(3 > 5); // false</pre>
<h3 id="数字和_BigInt_数据的比较">数字和 BigInt 数据的比较</h3>
<pre class="brush: js notranslate">console.log(5n > 3); // true
console.log(3 > 5n); // false</pre>
<h3 id="Boolean_null_undefined_NaN的比较">Boolean, null, undefined, NaN的比较</h3>
<pre class="brush: js notranslate">console.log(true > false); // true
console.log(false > true); // false
console.log(true > 0); // true
console.log(true > 1); // false
console.log(null > 0); // false
console.log(1 > null); // true
console.log(undefined > 3); // false
console.log(3 > undefined); // false
console.log(3 > NaN); // false
console.log(NaN > 3); // false</pre>
<h2 id="规范">规范</h2>
<table class="standard-table">
<tbody>
<tr>
<th scope="col">规范</th>
</tr>
<tr>
<td>{{SpecName('ESDraft', '#sec-relational-operators', 'Relational operators')}}</td>
</tr>
</tbody>
</table>
<h2 id="浏览器兼容">浏览器兼容</h2>
<p>{{Compat("javascript.operators.greater_than")}}</p>
<h2 id="参考">参考</h2>
<ul>
<li><a href="/en-US/docs/Web/JavaScript/Reference/Operators/Greater_than_or_equal">Greater than or equal operator</a></li>
<li><a href="/en-US/docs/Web/JavaScript/Reference/Operators/Less_than">Less than operator</a></li>
<li><a href="/en-US/docs/Web/JavaScript/Reference/Operators/Less_than_or_equal">Less than or equal operator</a></li>
</ul>
|