# javascript math function examples

JavaScript is client side programming language, we can perform all mathematical calculation using JavaScript, apart from using arithmetic logics, javascript math object has many built-in functionalities.

In JavaScript, Math is a global object with many in-built static properties and methods.

Here are few static properties of JavaScript Math Object like `Math.PI`, this Math property will return the Pie Value

```
document.write(" Math.PI : returns " + Math.PI);
document.write("<br>");
document.write(" Math.E : returns " + Math.E);
document.write("<br>");
document.write(" Math.SQRT2 : returns " + Math.SQRT2);
document.write("<br>");
document.write(" Math.LN2 : returns " + Math.LN2);
document.write("<br>");

```

## Built-in Math Functions in JavaScript

In this tutorial you will learn JavaScript Math Functions, that will allow you to perform many mathematical tasks on numbers.

1. Math.round in Javascript

Math.round(x) returns the rounded value of x, here is an example

```
document.write(" Math.round(8.6); : returns " + Math.round(8.6));
document.write("<br>");
document.write(" Math.round(8.4); : returns " + Math.round(8.4));
document.write("<br>");

```
2. `Math.ceil(), Math.floor()` in Javascript

Math.ceil(x) returns the rounded up to its nearest integer AND Math.floor(x) rounded down to its nearest integer:

```
document.write(" Math.ceil(8.6); : returns " + Math.ceil(8.6));
document.write("<br>");
document.write(" Math.floor(8.6); : returns " + Math.floor(8.6));
document.write("<br>");

```
3. Exponent `Math.pow()` in Javascript

Exponentiation using JavaScript, `Math.pow(x, y)` returns the value of x to the power of y (base to the exponent power).

```document.write(" Math.pow(10,2); :  returns " + Math.pow(10, 2));

```
4. `Math.sqrt()` in Javascript

square root function using Javascript, `Math.sqrt(x)` returns the square root value of x:

```
document.write(" Math.sqrt(100); : returns " + Math.sqrt(100));

```
5. Math.random()

`Math.random()` returns a random number between given range, 0 (inclusive), and 1 (exclusive):

```
document.write(" Math.random(); : returns " + Math.random());
document.write("<br>");
document.write(" Math.random(1,10); : returns " + Math.random(1, 10));
document.write("<br>");

```

6. `Math.max() and Math.min()`

Javascript max function `Math.max()` and min function `Math.min()` is used to find the lowest and highest value of any given arguments, let's look at the example below.

```
document.write("Math.max(10, 20, 37, 40, -50, -199, 400); : returns " + Math.max(10, 20, 37, 40, -50, -199, 400));
document.write("<br>");

```
7. Following function will find the lowest value from array.

```
document.write("Math.min(10, 20, 37, 40, -50, -199, 400); : returns " + Math.min(10, 20, 37, 40, -50, -199, 400));
document.write("<br>");

```
8. `Math.abs()`

Javascript abs function `Math.abs(x)` returns an absolute positive value of a number:

```
document.write("Math.abs(-10.50): returns " + Math.abs(-10.50));
document.write("<br>");

```
9. `Math.cos()`

cos function `Math.cos(x)` returns an Cosine value of a number:

```
document.write("Math.cos(15): returns " + Math.cos(15));
document.write("<br>");

```
10. `Math.tan()`

tan function ` Math.tan(x)` returns the tangent value of a number:

```
document.write("Math.tan(10): returns " + Math.tan(10));
document.write("<br>");

```
11. `Math.sin()`

Math.sin(x) returns the Sine value of a number:

```
document.write("Math.sin(10): returns " + Math.sin(10));
document.write("<br>");

```
12. `Math.log()`

Math.log(x) returns the logarithmic value of a number:

```
document.write("Math.log(10): returns " + Math.log(10));
document.write("<br>");

```