You've successfully subscribed to Smartcodehub ™ Blog
Welcome back! You've successfully signed in.

## The Math object | Javascript

Neeraj Dana

The Math object contains lots of utilities math-related. It contains constants and functions

### Variables In Math Object

1. Math.E : The constant e, base of the natural logarithm (means ~2.71828)
2. Math.LN10 : The constant that represents the base e (natural) logarithm of 10
3. Math.LN2 : The constant that represents the base e (natural) logarithm of 2
4. Math.PI : The π constant
5. Math.SQRT1_2 : The constant that represents the reciprocal of the square root of 2
6. Math.SQRT2 : The constant that represents the square root of 2

### Math Functions

Math.abs() : Returns the absolute value of a number

``````Math.abs(2.5) //2.5
Math.abs(-2.5) //2.5``````

Math.ceil() : returns a Rounded number Which is greater

``````Math.ceil(1.5) //2
Math.ceil(2) //2
Math.ceil(2.1) //3
Math.ceil(5.95) //6``````

Math.round() :  return a nearest integer

``````Math.round(1.4) //1
Math.round(2) //2
Math.round(2.1) //2
Math.round(5.95) //6``````

Math.floor() : returns a Rounded number Which is less

``````Math.floor(1.5) //1
Math.floor(2) //2
Math.floor(2.1) //2
Math.floor(5.95) //5``````

Math.log() : Return the base e (natural) logarithm of a number

``Math.log(10) //2.302585092``

Math.max() : Return the highest number in the set of numbers passed

``Math.max(1,2,3,4,5,6,7,8,9,10) => 10``

Math.min() : Return the lowest number in the set of numbers passed

``Math.max(1,2,3,4,5,6,7,8,9,10) => 1``

Math.pow() : Return the first argument raised to the second argument

``````2 to the power 2 = 2*2 = 4
Math.pow(2,2) => 4

2 to the power 3 = 2*2*2 = 8
Math.pow(2,3) => 8``````

Math.random() : Returns a pseudorandom number between 0.0 and 1.0

``Math.random()``

Math.sqrt() : Return the square root of the argument

``````Math.sqrt(4) //2
Math.sqrt(16) //4
``````