Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

Math.sign()

# The Math.sign() function returns either a positive or negative +/- 1, indicating the sign of a number passed into the argument


console.log(Math.sign(3));
// expected output: 1

console.log(Math.sign(-3));
// expected output: -1

console.log(Math.sign(0));
// expected output: 0

console.log(Math.sign('-3'));
// expected output: -1


A number representing the sign of the given argument:

If the argument is positive, returns 1.
If the argument is negative, returns -1.
If the argument is positive zero, returns 0.
If the argument is negative zero, returns -0.
Otherwise, NaN is returned.
Source by developer.mozilla.org #
 
PREVIOUS NEXT
Tagged:
ADD COMMENT
Topic
Name
1+9 =