X
HOME HTML CSS JAVASCRIPT SQL PHP JQUERY XML ASP.NET MORE...
REFERENCES | EXAMPLES | FORUM | ABOUT

JavaScript abs() Method

Math Object Reference JavaScript Math Object

Example

Return the absolute value of a number:

Math.abs(-7.25);

The result will be:

7.25

Try it yourself »


Definition and Usage

The abs() method returns the absolute value of a number.


Browser Support

Internet Explorer Firefox Opera Google Chrome Safari

The abs() method is supported in all major browsers.


Syntax

Math.abs(x)

Parameter Values

Parameter Description
x Required. A number

Return Value

Type Description
Number The absolute value of the specified number, or NaN if the value is not a number, or 0 if the value is null

Technical Details

JavaScript Version: 1.0


More Examples

Example

Return the absolute value of different numbers:

var a = Math.abs(7.25);
var b = Math.abs(-7.25);
var c = Math.abs(null);
var d = Math.abs("Hello");
var e = Math.abs(2+3);

The result of a,b,c,d, and e will be:

7.25
7.25
0
NaN
5

Try it yourself »


Math Object Reference JavaScript Math Object

Your suggestion:

Close [X]

Thank You For Helping Us!

Your message has been sent to W3Schools.

Close [X]
Search w3schools.com:

WEB BUILDING

Download XML Editor FREE Website BUILDER Free HTML5 Templates FREE Website Templates Free HTML Templates

SHARE THIS PAGE

facebook