Javascript Math Object

In Javascript Math object provides veriety of methods or function and properies that can be used to easily do mathematical calculations. Math object is an in-built object and so it is not required to instantiate the object as done for Date object.

Unlike the other global objects, Math is not a constructor. All properties and methods of Math are static.

Here is the simple syntax to call properties and methods of Math.


<title>Javascript Math Object</title>
var log_val = Math.LOG10E;
var sine_val = Math.sin(10);

Math Properties

Here is a list of each math property with description.

E Euler's constant and the base of natural logarithms, approximately 2.718.
LN2 Natural logarithm of 2, approximately 0.693.
LN10 Natural logarithm of 10, approximately 2.302.
LOG2E Base 2 logarithm of E, approximately 1.442.
LOG10E Base 10 logarithm of E, approximately 0.434.
PI Ratio of the circumference of a circle to its diameter, approximately 3.14159.
SQRT1_2 Square root of 1/2; equivalently, 1 over the square root of 2, approximately 0.707.
SQRT2 Square root of 2, approximately 1.414.

Math Functions

Here is a list of each function of math object with description.

abs() This will returns the absolute value of a number.
acos() This will returns the arccosine (in radians) of a number.
asin() This will returns the arcsine (in radians) of a number.
atan() This will returns the arctangent (in radians) of a number.
atan2() This will returns the arctangent of the quotient of its arguments.
ceil() This will returns the smallest integer greater than or equal to a number.
cos() This will returns the cosine of a number.
exp() This will returns EN, where N is the argument, and E is Euler's constant, the base of the natural logarithm.
floor() This will returns the largest integer less than or equal to a number.
log() This will returns the natural logarithm (base E) of a number.
max() This will returns the largest of zero or more numbers.
min() This will returns the smallest of zero or more numbers.
pow() This will returns base to the exponent power, that is, base exponent.
random() This will returns a pseudo-random number between 0 and 1.
round() This will returns the value of a number rounded to the nearest integer.
sin() This will returns the sine of a number.
sqrt() This will returns the square root of a number.
tan() This will returns the tangent of a number.

Javascript Math Example

<DOCTYPE html>
<TITLE>Example of Number Object</TITLE>
var no=Math.random()*10