#### JS Math

JS has some good collection of Math functions to handle various requirements. These functions we can inside our script based on the logic required. JavaScript consists of Math object that contains the functions and properties of mathematical operations. We can perform the actions like round figure the number to its nearest integer, evaluate the trigonometric angles using cos(), sin() and tan() functions. Math object also provides the functions like log(), sqrt(), random(), max(), min() etc. Following are the definitions for different types of JS Math Functions:

`Math.abs(a)     // the absolute value of aMath.acos(a)    // arc cosine of aMath.asin(a)    // arc sine of aMath.atan(a)    // arc tangent of aMath.atan2(a,b) // arc tangent of a/bMath.ceil(a)    // integer closest to a and not less than aMath.cos(a)     // cosine of aMath.exp(a)     // exponent of aMath.floor(a)   // integer closest to and not greater than aMath.log(a)     // log of a base eMath.max(a,b)   // the maximum of a and bMath.min(a,b)   // the minimum of a and bMath.pow(a,b)   // a to the power bMath.random()   // pseudorandom number in the range 0 to 1Math.round(a)   // integer closest to aMath.sin(a)     // sine of aMath.sqrt(a)    // square root of aMath.tan(a)     // tangent of a`

Note: Trigonometric functions assume that the argument is in radians, not degrees.

JS Math object also provides some properties along with functions. JavaScript Math object properties return the constant values for Math constants such as PI or E (i.e. Euler’s constant). Math object properties return pre-calculated values also e.g.: natural Log value of 2 or 10. Following are the JS Math object properties:

`Math.E:  returns the value of Euler’s constant. (2.718281828459045)Math.LN10:  returns the natural log of 10. (2.302585092994046)Math.LN2:  returns the natural log of 2. (0.6931471805599453)Math.LOG10E:  returns the base-10 log of E. (0.4342944819032518)Math.LOG2E:  returns the base-2 log of E. (1.4426950408889633)Math.PI:  returns the constant value of PI. (22/7 = 3.141592653589793)Math.SQRT1_2:  returns the value of square root of ½. (0.7071067811865476)Math.SQRT2:  returns the square root of 2. (1.4142135623730951)`

Above JavaScript Math properties return the predefined values for the constants like PI and E. Other properties like LOG10E, LN10, SQRT2 provides the pre- calculated values that reduces the code length by eliminating the logical code for deriving the values each time when they are required. We can directly use these JavaScript Math object properties.

The following JavaScript code shows the example of the Math object.

##### Example: Illustration of Math Object
`<html><body><script>document.write(Math.round(0.60) + "<br />");document.write(Math.round(0.50) + "<br />");document.write(Math.round(0.49) + "<br />");document.write(Math.round(-4.40) + "<br />");document.write(Math.round(-4.60) + "<br />");document.write(Math.random() + "<br />");document.write(Math.max(-3,-5) + "<br />");document.write(Math.max(7.25,7.30) + "<br />");document.write(Math.min(5,7) + "<br />");document.write(Math.min(-3,5) + "<br />");</script></body></html>`

Output:

`110-4-50.8561989925660989-37.35-3`