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.
|x| = √x2 ⇒ √-32 = 3
where x = -3
abs(number);
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);
abs(number);
mixed number |
It may be either integer or float |
Return |
Returns an number respective to an input (integer or float) |
abs(number);
// 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);
abs(number);
// 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);
abs(number);
// 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);