O'Reilly logo

jQuery and JavaScript Phrasebook by Brad Dayley

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Calculating Absolute Value

Math.abs(-5); //returns 5 Math.abs(5); //returns 5 Math.abs("-15"); //returns 15 Math.abs("0xFF"); //returns 255

The Math.abs(x) method returns the absolute value of x. The variable x can be a number or a numerical string such as "5", "-5", or "0xFF".

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required