| [ Web Proxy ] |
| Viewing: https://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/Global_Objects/Math/abs | [Back] [Original] |
Get to know MDN better
function difference(a, b) {
return Math.abs(a - b);
}
console.log(difference(3, 5));
// : 2
console.log(difference(5, 3));
// : 2
console.log(difference(1.23456, 7.89012));
// : 6.6555599999999995
Math.abs(x)
x x -0 -x x 0
abs() Math Math Math.abs() (Math )
Math.abs(-Infinity); //
Math.abs(-1); // 1
Math.abs(-0); // 0
Math.abs(0); // 0
Math.abs(1); // 1
Math.abs(Infinity); //
Math.abs("-1"); // 1
Math.abs(-2); // 2
Math.abs(null); // 0
Math.abs(""); // 0
Math.abs([]); // 0
Math.abs([2]); // 2
Math.abs([1, 2]); // NaN
Math.abs({}); // NaN
Math.abs("string"); // NaN
Math.abs(); // NaN
| ECMAScript 2027 LanguageSpecification # sec-math.abs |
| Web Proxy Viewer | New URL | Original Page |