The Fox Blog

JavaScript Math Functions

Posted in JavaScript by Fox on the February 11th, 2007

When coding in JavaScript, I always find the need to compute some basic mathematical values. The Math class (object) turns out to be useful here by providing numerous functions, such as sine, cosine or random number generator.
The list of JavaScript Math object functions below:

Math.abs(a) // absolute value of a
Math.acos(a) // arccosine of a
Math.asin(a) // arcsine of a
Math.atan(a) // arc tangent of a
Math.atan2(a, b) // arc tangent of (a / b)
Math.ceil(a) // ceiling of a
Math.cos(a) // cosine of a
Math.exp(a) // exponent of a
Math.floor(a) // floor of a
Math.log(a) // log of a base e
Math.max(a, b) // maximum of a and b
Math.min(a, b) // minimum of a and b
Math.pow(a, b) // a to the power b
Math.random() // random number from 0 to 1
Math.round(a) // rounded value of a
Math.sin(a) // sine of a
Math.sqrt(a) // square root of a
Math.tan(a) // tangent of a