# Math Objects In JavaScript

 Math object provides many properties and functions which allows to perform complex mathematical work. A Math object is a built in object of JavaScript using which a lot of mathematical calculations can be performed. We can use these mathematical functions to create the animation in JavaScript also Math object properties E- this property returns Euler’s Constant (rougly 2.718) PI- this property returns the value of PI Length – property returns the no of characters present in string. Math object Methods abs() – this function calculates and returns the absolute value. ceil() – this function returns the next greater or equal integer.. cos() – this function is used to calculate the cosine number.. sin()– this function is used to calculate the sin() of a number. random () – this function returns a randomly calculated number between 0 and 1. . sqrt() – this function calculates and returns the square root of a number. tan() – this function calculates and returns tangent of a number. floor() – this function returns next integer lesser than or equal to a number.. pow() – this function returns calculated value of one number for given number of powers. bold() – returns the string formatting to bold. italics() – returns the string formatting italics. charAt() – returns the character present in string at given position. substring() – returns the characters present from given start position to given end position. toLowerCase() – returns the string converted to lowercase letters. toUpperCase() – returns the string converted to uppercase letters. Math Object’s abs() function This function calculates and returns the absolute value. Suppose the value of any variable is –345 the absolute value of –345 will be 345. if the value of a variable is 345 then the absolute value of variable will be 345. Example: click here to view the results of this program in browser Math Object’s ceil() function ceil()- this function returns the next greater or equal integer. If any number is having a decimal value then the value is increased with one else it remains as it is. Fox example a variable is having value 45.26 then the ceiling value of this variable will be 45 but if the variable value is 25 the ceil value will be 25 only. Example: click here to view the results of this program in browser Math Object’s cos() function cos()- this function is used to calculate the cosine number. Math object contains cos() function which can return the cos value of the angle provided with the cos function. Examples: click here to view the results of this program in browser Math Object’s floor() function floor()- this function returns next integer lesser than or equal to a number. If any value is having the decimal values with it floor function provides the decimal truncated value. Fox example a variable is having value 45.26 the floor value of that variable will be 45 but if the value is 32 then the floor value of variable will be 32 only. Example: click here to view the results of this program in browser Math Object’s pow() function pow()- this function returns calculated value of one number for given number of powers. For example if the parameters passed to the function are 2 , 3 then the answer will be 8 , 2*2*2 = 8 , this function requires the base and the power of the value and returns the calculated value. Example: click here to view the results of this program in browser Math Object’s random() function random ()- this function returns a randomly calculated number between 0 and 1. The Math object contains a random function which can be used to get the randomly generated value between 0 & 1, The code given below will generated a random value but if refreshed every time it will generate a new randomly generated value. Example:
On Refresing screen every time new number between 0 & 1
will be generated by random function
click here to view the results of this program in browser Math Object’s sin() function sin()- this function is used to calculate the sin() of a give number. Math object contains sin function which can be used to get the sin value of any angle given to sin function as parameter. In the below given example we are passing different angle values to sin function which will generate different values Example: click here to view the results of this program in browser Math Object’s sqrt() function sqrt()- this function calculates and returns the square root of a number. Math object has a sqrt function used to get the square root of the number given with function. Fox example if the variable value or value given to sqrt function is 81 then it will return 9 because the square root of 81 is 9. Example: click here to view the results of this program in browser Math Object’s sqrt() function tan()- this function calculates and returns tangent of a number. This function will return the value generated of the angle given with tan function. Example:
Scroll to Top