Math.sign()

ES6+

Returns the sign of a number, indicating whether the number is positive, negative, or zero.

Syntax

Math.sign(x)

Parameters

x number

A number

Return Value

number

1, -1, or 0 indicating the sign of the number

Examples

JavaScript
console.log(Math.sign(5));
console.log(Math.sign(-5));
console.log(Math.sign(0));
Output:
// 1 -1 0

Related Methods