Last Updated : 15 Jul, 2024
The Math.sign() is a built-in method in JavaScript and is used to know the sign of a number, indicating whether the number specified is negative or positive.
Syntax:Math.sign(number)Parameters:
The Math.sign() method returns five different values as described below:
Example 1: When a positive number is passed as an argument.
JavaScript
console.log(Math.sign(2));
Example 2: When a negative number is passed as an argument:
JavaScript
console.log(Math.sign(-2));
Example 3: When a positive zero is passed as an argument:
JavaScript
console.log(Math.sign(0));
Example 4: When a negative zero is passed as an argument:
JavaScript
console.log(Math.sign(-0));
Example 5: When an invalid number is passed as an argument:
JavaScript
console.log(Math.sign(haa));
Output:
NaN
We have a complete list of Javascript Math Objects methods, to check those please go through this Javascript Math Object Complete reference article.
Supported BrowsersRetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4