X
HOME HTML5 CSS3 JAVASCRIPT SQL PHP5 JQUERY ANGULAR BOOTSTRAP3 XML 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 »

More "Try it Yourself" examples below.


Definition and Usage

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


Browser Support

Method
abs() Yes Yes Yes Yes Yes


Syntax

Math.abs(x)

Parameter Values

Parameter Description
x Required. A number

Technical Details

Return Value: A Number, representing the absolute value of the specified number, or NaN if the value is not a number, or 0 if the value is null
JavaScript Version: 1.0


Examples

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 HOSTING

UK Reseller Hosting

WEB BUILDING

Download XML Editor FREE Website BUILDER Free HTML5 Templates

SHARE THIS PAGE

facebook