abs()
Math
class methodS2C Home
« Globals « Math « abs()
Description
Returns the absolute value of a number.
- Like all class methods
abs()
should be used on the class rather than an instance of the class.
Syntax
Signature | Description |
---|---|
Math.abs(value) | Returns the absolute value of a number. |
Parameters
Parameter | Description |
---|---|
value | The value you wish to find the absolute number of: |
Examples
The code below displays abs()
usage.
/*
* Store results in an array.
*/
var absValues = new Array(6);
absValues[0] = Math.abs(1);
absValues[1] = Math.abs(-10);
absValues[2] = Math.abs('100');
absValues[3] = Math.abs('five');
absValues[4] = Math.abs();
absValues[5] = Math.abs(null);
alert(absValues);
Related Tutorials
JavaScript Advanced Tutorials - Lesson 4 - Math