Easy Tutorial
❮ Met Win Matchmedia Met Video Pause ❯

JavaScript Math Object


Math Object

The Math object is used to perform mathematical tasks.

Unlike Date and String, the Math object is not a constructor, so it does not have a Math() constructor.

Syntax

var x = Math.PI; // Returns PI
var y = Math.sqrt(16); // Returns the square root of 16

For a tutorial on the Math object, please refer to the JavaScript Math Object Tutorial.


Math Object Properties

Property Description
E Returns the mathematical constant e, the base of the natural logarithm (approximately 2.718).
LN2 Returns the natural logarithm of 2 (approximately 0.693).
LN10 Returns the natural logarithm of 10 (approximately 2.302).
LOG2E Returns the base 2 logarithm of e (approximately 1.4426950408889634).
LOG10E Returns the base 10 logarithm of e (approximately 0.434).
PI Returns the ratio of the circumference of a circle to its diameter (approximately 3.14159).
SQRT1_2 Returns the square root of 1/2 (approximately 0.707).
SQRT2 Returns the square root of 2 (approximately 1.414).

Math Object Methods

Method Description
abs(x) Returns the absolute value of x.
acos(x) Returns the arccosine of x.
asin(x) Returns the arcsine of x.
atan(x) Returns the arctangent of x as a numeric value between -PI/2 and PI/2 radians.
atan2(y,x) Returns the angle from the X-axis to a point (x,y).
ceil(x) Rounds a number up to the nearest integer.
cos(x) Returns the cosine of a number.
exp(x) Returns E^x.
floor(x) Rounds a number down to the nearest integer.
log(x) Returns the natural logarithm (base e) of a number.
max(x,y,z,...,n) Returns the number with the highest value.
min(x,y,z,...,n) Returns the number with the lowest value.
pow(x,y) Returns the value of x to the power of y.
random() Returns a random number between 0 and 1.
round(x) Rounds a number to the nearest integer.
sin(x) Returns the sine of a number.
sqrt(x) Returns the square root of a number.
tan(x) Returns the tangent of an angle.
tanh(x) Returns the hyperbolic tangent of a number.
trunc(x) Returns the integer part of a number by removing any fractional digits.
❮ Met Win Matchmedia Met Video Pause ❯