JavaScript(JS) math method - sign

ww‮w‬.theitroad.com

The sign method in JavaScript's Math object returns the sign of a number. The sign method takes a single argument, which is the number to check the sign of. If the number is positive, 1 is returned; if the number is negative, -1 is returned; if the number is zero, 0 is returned.

Here's an example usage:

const num1 = 10;
const num2 = -10;
const num3 = 0;
console.log(Math.sign(num1)); // 1
console.log(Math.sign(num2)); // -1
console.log(Math.sign(num3)); // 0

In the above example, the Math.sign method is used to check the sign of the numbers 10, -10, and 0. The results, which are 1, -1, and 0, respectively, are then logged to the console.