JavaScript Math.sign()

Example 1

let x = Math.sign(3);
Try it Yourself »

Description

The Math.sign() method retuns whether a number is negative, positive or zero.

If the number is positive, this method returns 1.
If the number is negative, it returns -1.
If the number is zero, it returns 0.

Example 2

let x = Math.sign(-3);
Try it Yourself »

Example 3

let x = Math.sign(0);
Try it Yourself »

Browser Support

Math.sign() is an ECMAScript6 (ES6) feature.

ES6 (JavaScript 2015) is supported in all modern browsers since June 2017:

Chrome 51 Edge 15 Firefox 54 Safari 10 Opera 38
May 2016 Apr 2017 Jun 2017 Sep 2016 Jun 2016

Math.sign() is not supported in Internet Explorer.


Syntax

Math.sign(x)

Parameters

Parameter Description
x Required. A number.

Return Value

A Number, representing the sign of the specified number:
  • If the number is positive, it returns 1
  • If the number is negative, it returns -1
  • If the number is positive zero, it returns 0
  • If the number is negative zero, it returns -0
  • If the number is not a number, it returns NaN

Copyright 1999-2023 by Refsnes Data. All Rights Reserved.