abs()  Math  class method JS Home  <<  JS Reference  <<  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
valueThe value you wish to find the absolute number of:
  • Non-numeric strings returns NaN.
  • Passing no parameter returns NaN.
  • Passing null returns 0.

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);  

Press the button below to action the above code:

Related Tutorials

JavaScript Advanced Tutorials - Lesson 4 - Math

JavaScript Basics

JavaScript Basics

JavaScript Intermediate

JavaScript Intermediate

JavaScript Advanced

JavaScript Advanced

JavaScript Reference

JavaScript Entities

Globals

Math

Class Properties
E
LN2
LN10
LOG2E
LOG10E
PI
SQRT1_2
SQRT2
Instance Properties
None.
Class Methods
abs()
acos()
asin()
atan()
atan2()
ceil()
cos()
exp()
floor()
log()
max()
min()
pow()
random()
round()
sin()
sqrt()
tan()
Instance Methods Getters
None.
Instance Methods Setters
None.

Statements

Operators