A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://developer.mozilla.org/ko/docs/Web/JavaScript/Reference/Global_Objects/Math/abs below:

Math.abs() - JavaScript | MDN

Math.abs()

Baseline Widely available

Math.abs() 정적 메서드는 숫자의 절대 값을 반환합니다.

시도해 보기
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를 반환합니다. 따라서 결과는 언제나 양수 혹은 0입니다.

설명

abs()는 Math의 정적 메서드이기 때문에, 생성한 Math 객체(Math는 생성자가 아닙니다)의 메서드 대신 언제나 Math.abs()를 사용해야 합니다.

예제 Math.abs() 사용하기
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