abs(x)

Introduction

The abs(x) function returns the absolute value of x.

Form

The following is the syntax for the abs(x) function.

Math.abs(x);

Use

Example

The following is the code for the abs(x) function.

document.write(Math.abs(0.5));

On running the above code, the following output is obtained.

Example

The following is the code for the abs(x) function.

document.write(Math.abs(-0.5));

On running the above code, the following output is obtained.