Math.sign

sign — Check if the number is positive, negative or zero.

Description

Math.sign(number number)

Parameters

Name Description Type Default Optional
number number No

Return values

mixed. Integer (1, 0, -0, 1) for numbers or NaN for non number input.

Changelog

Version Description
ES 6 Introduced.

Examples

Example #1 – sign example
console.log(Math.sign(10)); // 1 console.log(Math.sign(0)); // 0 console.log(Math.sign(-5)); // -1 console.log(Math.sign(-0)); // -0 console.log(Math.sign('8')); // 1 console.log(Math.sign('string')); // NaN

External references