Baseline Widely available
Math.abs(x)
彿°è¿åä¸ä¸ªæ°åçç»å¯¹å¼ã
function difference(a, b) {
return Math.abs(a - b);
}
console.log(difference(3, 5));
// Expected output: 2
console.log(difference(5, 3));
// Expected output: 2
console.log(difference(1.23456, 7.89012));
// Expected output: 6.6555599999999995
è¯æ³ åæ° è¿åå¼
x
çç»å¯¹å¼ã妿 x
æ¯è´æ°ï¼å
æ¬ -0
ï¼ï¼åè¿å -x
ãå¦åï¼è¿å x
ã
ç±äº abs()
æ¯ Math
ä¸çä¸ä¸ªéææ¹æ³ï¼æä»¥ä½ åºè¯¥éè¿ Math.abs()
è°ç¨ï¼è䏿¯ä½ä¸ºä½ å建ç Math
å¯¹è±¡çæ¹æ³ï¼Math
䏿¯æé å¨ï¼ã
Math.abs(-Infinity); // Infinity
Math.abs(-1); // 1
Math.abs(-0); // 0
Math.abs(0); // 0
Math.abs(1); // 1
Math.abs(Infinity); // Infinity
强å¶è½¬æ¢åæ°
Math.abs()
å°å
¶åæ°å¼ºå¶è½¬æ¢ä¸ºæ°åãæ æ³å¼ºå¶è½¬æ¢çå¼å°åæ NaN
ï¼ä½¿ Math.abs()
ä¹è¿å NaN
ã
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
è§è æµè§å¨å
¼å®¹æ§ åè§
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4