大于 (>)
如果左操作数大于右操作数,则大于 (>) 运算符返回 true,否则返回 false。
¥The greater than (>) operator returns true if the left
operand is greater than the right operand, and false otherwise.
Try it
语法
描述
¥Description
使用与 少于 运算符相同的算法来比较操作数,只不过交换了两个操作数。x > y 通常等同于 y < x,只不过 x > y 在 y 之前将 x 强制为原语,而 y < x 在 x 之前将 y 强制为原语。由于强制转换可能会产生副作用,因此操作数的顺序可能很重要。
¥The operands are compared using the same algorithm as the Less than operator, except the two operands are swapped. x > y is generally equivalent to y < x, except that x > y coerces x to a primitive before y, while y < x coerces y to a primitive before x. Because coercion may have side effects, the order of the operands may matter.
示例
字符串与字符串的比较
字符串与数字的比较
数字与数字的比较
数字与 BigInt 比较
比较布尔值、null、未定义、NaN
规范
| Specification |
|---|
| ECMAScript Language Specification # sec-relational-operators |
浏览器兼容性
BCD tables only load in the browser
也可以看看
¥See also