Math Object In JavaScript

 

Math Object In JavaScript

    In JavaScript to perform mathematical tasks or operations on numbers, we use Math objects. In JavaScript unlike other objects Math object has no constructor. In JavaScript for Math object there is no need to create object first, we use all methods and properties without creating math object. 
    There is no need to create the math object before using it.

Math Properties-

Math property syntax- Math.property

In JavaScript, there are 8 mathematical constants and these are used as math properties.
Sr.No. Property Description
1. Math.E Returns the Euler's Number i.e.Math.E: 2.718281828459045
2. Math.PI Returns the PI i.e.Math.PI: 3.141592653589793
3. Math.SQRT2 Returns square root of 2.i.e.Math.SQRT2: 1.4142135623730951
                
4. Math.LN2 Natural Algorithm of 2
5. Math.LN10 Natural Algorithm of 10
6. Math.LOG2E Base 2 Logarithm of E
7. Math.LOG10E Base 10 logarithm of E
8. Math.SQRT1_2 Square root of 1/2

Math object Methods-


Sr.No. Method Description Syntax
1. abs(x) Returns the absolute value of a number. Math.abs(x).
2. ceil(x) returns the value of x rounded up to its next greater than or equal to given number. Math.ceil(x)
3. floor(x) Returns the value of x rounded upto its next less or equal to given number. Math.floor(x)
4. max(num1,num2,num3) Returns the highest value in list of numbers Math.max(number1,number2,number3....)
5. min(num1,num2,num3) Returns the lowest value in list of numbers Math.min(number1,number2,number3....)
6. sqrt(x) Returns the square root of given number Math.sqrt(x)
7. cbrt(x) Returns the cube root of given number Math.cbrt(x)
8. random() Returns the random between 0 and 1. Math.random()

Previous
Next Post »

Please Comment and Share. ConversionConversion EmoticonEmoticon