 # JavaScript Math And Its Functions

In this tutorial, you will learn about Math object in JavaScript. You will learn about all the functions available in the Math object with examples.

In javascript, Math is a built-in object which has many properties and methods that are used to deal with mathematical constants and functions like PI, sin, cos, etc.

Math is not a constructor, Unlike Array or String. All the methods and properties of Math are static, meaning you can directly use methods and properties without creating objects. example `Math.PI`, `Math.sin(x)` etc.

Note: Static methods and properties belong to the class not to its object. All the methods and properties can be called on `Math` as an object. The Math object has many properties and methods which is used to get values of mathematical constants and functions like E, Log2, PI, sin, cos, etc.

Let's see the list of all the properties and methods of the Math object.

## Math Object Properties

The following table lists all the properties of the Math object.

PropertyDescription
Math.PIReturns the value of mathematical constant PI (ratio of circumference to diameter)
Math.EReturns Euler's constant (base of natural logarithm)
Math.LN2Returns the value of the natural logarithm of 2 (approx 0.693)
Math.LN10Returns the value of the natural logarithm of 10 (approx 2.302)
Math.LOG2EReturns the value of base 2 logarithm of e (approx 1.443)
Math.LOG10EReturns the value of base 10 logarithm of e (approx 0.434)
Math.SQRT1_2Returns the value of the square root of 1/2 (approx 0.707)
Math.SQRT2Returns the value of the square root of 2 (approx 1.414)

### Math.PI

PI is a static property of the Math object. It returns the value of mathematical PI (π).

You can use π to calculate the area of the circle.

### Math.E

E is a static property of the Math object. It returns the value of mathematical constant E (2.718281828459045). Used as Math.E.

Value of E is used in logarithm function, probability, etc.

### Math.LN2

LN2 is a static property of a Math object. It returns the value of the natural logarithm of 2 (approx 0.693).

### Math.LN10

Similar to LN2, LN10 is a static property of a Math object. It returns the value of natural logarithm of 10 (approx 2.302).

### Math.LOG2E

LOG2E is also a static property of a Math object. It returns the value of base 2 logarithm of e (approx 1.443).

### Math.LOG10E

LOG10E means base 10 logarithm of e (log10e). It is a static property of Math object. It returns a value approx 0.434.

### Math.SQRT1_2

To get the value of the square root of 1/2 (√½), use the SQRT1_2 property of the Math object. It returns a value of approx 0.707.

### Math.SQRT2

To get the value of square root of 2 (√2), use SQRT2 property of Math object. It returns a value approx 1.414.

## Javascript Math methods

There are many methods available in Math object. They are as follows:

MethodDescription
Cosine Functions
Math.cos(x)Returns the cosine of x
Math.cosh(x)Returns the hyperbolic cosine of x
Math.acos()Returns the arccosine of a given number in radian
Math.acosh()Returns the hyperbolic arccosine of a number
Sine Functions
Math.sin(x)Returns the sine of x
Math.sinh(x)Returns the hyperbolic sine of x
Math.asine()Returns the arcsine of given number in radian
Math.asinh()Returns the hyperbolic arccosine of a number
Tangent Functions
Math.tan()Returns the tangent of given number in radian
Math.atan()Returns the arctangent of given number in radian
Math.atan2(y,x)Returns the arctangent of quotient of its argument
Math.atanh(y,x)Returns the hyperbolic arctangent of x
Math.tanh()Returns the hyperbolic tangent of a number
Min/Max Functions
Math.min()Returns the smallest of the given numbers
Math.max()Returns the largest of the given numbers
Upper/Lower Bound Functions
Math.ceil(x)Returns the smallest integer greater than or equal to x
Math.floor(x)Returns the largest integer less than or equal to x
Logarithemic Functions
Math.log(x)Returns the natural logarithm of x (loge )
Math.log10(x)Returns the base-10 logarithm of x
Math.log2(x)Returns the base-2 logarithm of x
Math.exp(x)Returns the Ex, where E is Euler number
Misscelenious Functions
Math.pow(x,y)Returns base x to exponent y ( xy )
Math.random()Returns a random number between 0 and 1
Math.round(x)Returns the value of number rounded to nearest integer
Math.abs(x)Returns the absolute value of x
Math.sign(x)Returns sign of x, +ve -ve or 0
Math.sqrt(x)Returns the square root of x
Math.cbrt(x)Returns the cube root of x

### JavaScript sin functions

Sine functions in javascript are used to get the value of different sin trigonometric functions like `sin`, `asin`, `sinh`, and `asinh`

Here is an example of each function with its description.

### JavaScript cos functions

Cosine functions in javascript are used to get the value of different cos trigonometric functions like `cos`, `acos`, `cosh`, and `acosh`

Here is example of each cos function with its description.

### JavaScript tan functions

Tan functions in javascript are used to get value of different tan trigonometric functions like `tan`, `atan`, `atan2`, `tanh`, and `atanh`

Here is example of each tan function with its description.

### JavaScript min max functions

Min and max functions in javascript are used to get the minimum and maximum value of two numbers or more numbers.

Here is an example of each min and max function with its description.

### JavaScript log functions

Log functions in javascript are used to get value of different log trigonometric functions like `log`, `log10`, `log2`, and `exp`.

Here is an example of each log function with its description.

### JavaScript abs method

The `Math.abs(x)` method return absolute value of x.

### JavaScript ceil and floor Method

The `Math.floor(x)` method return the largest number less than or equal to x.

The `Math.ceil(x)` method return the smallest number greater than or equal to x.

### JavaScript random function

The `Math.random()` method returns a random number in between 0 and 1.

This method can be used to get a random number between any integer.

### JavaScript round method

The `Math.round(x)` method returns the value of the round number nearest to x.

## Conclusion

JavaScript Math object gives us many useful mathematical functions. We can use these functions to calculate the value of any mathematical expression.

In this article, we have covered all the properties and methods of Math object in javascript.