javaScript Math Object

the javascript math object used to perform mathematical tasks.

the math object that provides basic mathematics functionality and constants.

note: you cannot create an instance of the math object.

syntax:

          math.[ property     |    method ]
   <script>
   
       document.write("the base of the natural log___"+math.e+
       
                      "<br/>natural logarithm of 2___"+math.ln2+
                      
                      "<br/>natural logarithm of 3___"+math.ln10+
                      
                      "<br/>pi value____"+ math.pi+
                      
                      "<br/>square root of 2____"+math.sqrt2);
                      
                       </script>
     document.write("<br/>"+"the squre root_____"+math.sqrt(444));
 
     document.write("<br/>"+"the floor value_____"+math.floor(1.56));
                    
     document.write("<br/>"+"the ceil value______"+math.ceil(4.23));
                    
     document.write("<br/>"+"the power of  value____"+math.pow(10,5));
                    
     document.write("<br/>"+"the min value ______"+math.min(20,40));
                    
     document.write("<br/>"+"the max value_______"+math.max(20,40));

note : all the properties of the math object are static and read-only.

note : all the methods of the math object are static.

javaScript math object properties

propertydescription
ereturns the base of the natural logarithm
ln2returns the natural logarithm of 2
ln10returns the natural logarithm of 10
log2ereturns the base-2 logarithm of e
log10ereturns the base-10 logarithm of e
pireturns pi
sqrt1 2returns the square root of 1/2
sqrt2returns the square root of 2

javaScript math object methods

methoddescription
abs(y)returns the absolute value of y
acos(y)returns the arc cosine of y
asin(y)returns the arc sine of y
atan(y)returns the arc tangent of y
atan2(x,y)returns the arc tangent of the quotient of its arguments
ceil(y)returns y, rounded upwards to the nearest integer
cos(y)returns the cosine of x
exp(y)returns the value of ey
floor(y)returns y, rounded downwards to the nearest integer
log(y)returns the natural logarithm
max(x,y)returns the number with the highest value
min(x,y)returns the number with the nearest integer
pow(x,y)returns the value of x to the power of y
random()returns a random number between 0 and 1
round(y)returns y to the nearest integer
sin(y)returns the sine of x
sqrt(y)returns the square root of y
tan(y)returns the tangent of an angle