Math functions in Javascript provide the functionality for mathematical functions. Javascript consists of Math object that contains the functions and properties of mathematical operations. You 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 Javascript Math Functions and properties:
Math.abs(x): abs function returns the absolute value of the specified number.
Math.acos(x): acos function returns the arc cosine of a number.
Math.asin(x): asin function returns the arc sine of a number.
Math.atan(x): atab function returns the arc tangent of a number.
Math.atan2(x,y): atan2 accepts two values as x and y and returns the arc tangent of the quotient of the x and y.
Math.ceil(x): ceil function returns the nearest integer rounded off to greater than or equal to the specified number.
Math.cos(x): cos function returns the cosine of number.
Math.exp(x): exp function returns the Ex (E: stands for Euler’s constant).
Math.floor(x): floor function returns the nearest integer rounded off to smaller than or equal to the specified number.
Math.log(x): log function returns the natural log of base E of the specified number.
Math.max(x,y): max function returns the greater number among two values as x and y passed to the function.
Math.min(x,y): min function returns the smaller number among two values as x and y passed to the function.
Math.pow(x,y): pow function returns the value of x to the power y e.g.: xy
Math.random(): random function returns the random number between 0 and 1 each time it is called.
Math.round(x): round function returns the value to its nearest integer.
Math.sin(x): sin function returns the sine value of a number.
Math.sqrt(x): sqrt function calculates and returns the square root of the specified number.
Math.tan(x): tan function returns the tangent of number.
Note: Trigonometry function evaluates the value for the specified number assuming that passed value for theta is in Radian not in Degree.
In the next article we will learn about the Javascript Math Object Properties.
Be the first to rate this post
Tags: javascript, javascript math functions, javascript math object, javascript math properties, javascript math.abs, javascript math.ceil, javascript math.floor, javascript math.pow, javascript math.round, javascript math.random, javascript math.log, javascript math.sqrt
8/23/2008 8:49:19 PM