Deprecated: mysql_connect(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in /home3/bbminfoc/public_html/Server/DB/Connection.php on line 93
JavaScript abs Math Function - Absolute Value
BBMINFO Tutor

JS Math Function - abs()

Description & Uses of JS abs()

The JS abs() function is used to return the absolute value or modulus |x| of a real number x is the non-negative value of x without regard to its sign.

Formula

|x| = √x2 ⇒ √-32 = 3

where x = -3

Simple Example - JS abs(number);

JS Input Screen

Plain text
const a = abs(0) // Integer Value
const b = abs(-3) // Negative Value
const c = abs(2.53) // Float Value
const d = abs(Infinity) // ∞ - Infinity Value
 
console.log("The value of abs(0) is " + a);
console.log("The value of abs(-3) is " + b);
console.log("The value of abs(2.53) is " + c);
console.log("The value of abs(Infinity) is " + d);

JS Output Screen

The value of abs(0) is 0
The value of abs(-3) is 3
The value of abs(2.53) is 2.53
The value of abs(Infinity) is Infinity

JS abs - Absolute value in other languages

Simple JS Syntax

  1. abs(number);

Parameter & Return Type

mixed number It may be either integer or float
Return Returns an number respective to an input (integer or float)

Example #1 Integer Values - JS abs(number);

JS Input Screen

Plain text
// Absoulte Value - Positive Integer Values
const a = abs(6)
const b = abs(0)
 
console.log("The value of abs(6) is " + a);
console.log("The value of abs(0) is " + b);
 
// Absoulte Value - Negative Integer Values
const c = abs(-3)
const d = abs(-0)
 
console.log("The value of abs(-3) is " + c);
console.log("The value of abs(-0) is " + d);

JS Output Screen

The value of abs(6) is 6
The value of abs(0) is 0
The value of abs(-3) is 3
The value of abs(-0) is 0

Example #2 Float Values - JS abs(number);

JS Input Screen

Plain text
// Absoulte Value - Positive Float Values
const a = abs(3.14)
const b = abs(0.00)
 
console.log("The value of abs(3.14) is " + a);
console.log("The value of abs(0.00) is " + b);
 
// Absoulte Value - Negative Float Values
const c = abs(-0.56)
const d = abs(-0.00)
 
console.log("The value of abs(-0.56) is " + c);
console.log("The value of abs(-0.00) is " + d);

JS Output Screen

The value of abs(3.14) is 3.14
The value of abs(0.00) is 0
The value of abs(-0.56) is 0.56
The value of abs(-0.00) is 0

Example #3 ∞ Infinite Values - JS abs(number);

JS Input Screen

Plain text
// Absoulte Value - Positive ∞ Infinite Value
const a = abs(Infinity)
 
console.log("The value of abs(Infinity) is " + a);
 
// Absoulte Value - Negative ∞ Infinite Value
const b = abs(-Infinity)
 
console.log("The value of abs(-Infinity) is " + b);

JS Output Screen

The value of abs(Infinity) is Infinity
The value of abs(-Infinity) is Infinity