Maths Method in JavaScript

Maths Method in JavaScript
0.0 0

#1

Hello folks, i’m a beginner in JavaScript. Please can someone throw some lights on Absolute Number(Maths Method). Also this two line of codes gives same result:

var a = 6;
console.log("absolute value of a is " + Math.abs(a) + “.”); //absolute value of a is 6

and
var a = 6;
console.log("absolute value of a is " + a + “.”); // absolute value of a is 6

my question now is , what is the function of Math.abs() in the first line of code if i can just insert variable a and still get the same result


#2

Try with minus sign before value and you’ll see the difference.
var a = -6;
Math.abs(a)
console.log("absolute value of a is " + Math.abs(a) + “.”); //absolute value of a is 6


var a = -6;
console.log("absolute value of a is " + a + “.”); // absolute value of a is -6

Absolute values removes sign. Negative becomes positive, and positive becomes positive.


#3

Thank you boss, well explained.