📜  Math.sign - Javascript 代码示例

📅  最后修改于: 2022-03-11 15:01:30.060000             🧑  作者: Mango

代码示例1
//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