Math.sign()
Math.sign() 静态方法返回 1 或 -1,指示作为参数传递的数字的符号。如果输入为 0 或-0,则按原样返回。
¥The Math.sign() static method returns 1 or -1, indicating the sign of the number passed as argument. If the input is 0 or -0, it will be returned as-is.
Try it
语法
参数
返回值
¥Return value
代表 x 符号的数字:
¥A number representing the sign of x:
- 如果
x为正,则返回1。 - 如果
x为负数,则返回-1。 - 如果
x为正零,则返回0。 - 如果
x为负零,则返回-0。 - 否则,返回
NaN。
描述
示例
使用 Math.sign()
规范
| Specification |
|---|
| ECMAScript Language Specification # sec-math.sign |
浏览器兼容性
BCD tables only load in the browser