JavaScript math sign() method

The JavaScript math sign() method is used to get the sign of a number.
Syntax:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
Math.sign(n)
Math.sign(n)
Math.sign(n)

Parameters
n: It represents the number whose sign has to be get.

Returns
Sign of a number.

Example:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<!DOCTYPE html>
<html>
<body>
<script>
document.writeln(Math.sign(-6));
</script>
</body>
</html>
<!DOCTYPE html> <html> <body> <script> document.writeln(Math.sign(-6)); </script> </body> </html>
<!DOCTYPE html>
<html>
<body>
<script>
document.writeln(Math.sign(-6));
</script>
</body>
</html>