Math.sign() function in JavaScript


The sign() function of the Math object accepts an integer number and returns its sign.(positive, negative)

  • If the given number is a positive integer then, this function returns +1.
  • And, if the given number is a negative integer then, this function returns -1.

Syntax

Its Syntax is as follows

Math.sign();

Example

 Live Demo

<html>
<head>
   <title>JavaScript Example</title>
</head>
<body>
   <script type="text/javascript">
      var result = Math.sign(-128);
      document.write("Result: "+result);
   </script>
</body>
</html>

Output

Result: -1

Samual Sam
Samual Sam

Learning faster. Every day.

Updated on: 25-Jun-2020

53 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements