Favorites

JavaScript Math.abs() Method

☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee
Math.abs()
JavaScript Math Static methodThis method is supported by all modern browsers.
Updated 28th November 2026

The Math.abs() static method returns the absolute value of a number: its distance from zero, without a minus sign.

Description

The Math.abs() static method returns the absolute value of a number, so negative numbers become positive and positive numbers stay the same. It's used to measure the difference between two values regardless of which is larger.

Math.abs(-0) returns 0, Math.abs(-Infinity) returns Infinity, and anything that can't be converted to a number returns NaN. Numeric strings are converted first, so Math.abs('-3') is 3.

A common use is checking whether two numbers are close enough to count as equal, as in Math.abs(a - b) < 0.001, which avoids problems with floating point rounding. Like every member of Math, it's called on the Math object itself rather than on a number, and it only works with the Number type: passing a BigInt throws a TypeError.

Syntax

Math.abs(x)

Parameters

  • xA number.

Return Value

The absolute value of x.

Example

console.log(Math.abs(-7.25));
console.log(Math.abs(3));
const diff = (a, b) => Math.abs(a - b);
console.log(diff(3, 10), diff(10, 3));

Browser Support

The following information will show you the current browser support for the Math.abs() method. Hover over a browser icon to see the version that first introduced support for this method.

This method is supported by all modern browsers.

Desktop

Chrome
Edge
Firefox
Opera
Safari

Tablets & Mobile

Chrome Android
Firefox Android
Opera Android
Safari iOS
Samsung Internet
Android WebView
-
Supported Unknown Not supported
☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee