“Math.sign” Respostas de código

Math.sign

//The Math.sign() function returns either a positive or negative +/- 1,
//indicating the sign of a number passed into the argument. If the number passed into 
//Math.sign() is 0, it will return a +/- 0. Note that if the number is positive,
//an explicit (+) will not be returned.

Math.sign(3);     //  1
Math.sign(-3);    // -1
Math.sign('-3');  // -1
Math.sign(0);     //  0
Math.sign(-0);    // -0
Math.sign(NaN);   // NaN
Math.sign('foo'); // NaN
Math.sign();      // NaN
Scary Snake

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.
Irfan

javascript Math.sign ()

Math.sign(-4);
Math.sign(0);
Math.sign(4);
naly moslih

Respostas semelhantes a “Math.sign”

Procure respostas de código populares por idioma

Procurar outros idiomas de código