# Math function in JavaScript....

So in this blog, we are going to understand what is Math function in javaScript, also understand where we should use this

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1693298267654/64a46e44-c06b-45a3-a81c-cdf0286c9644.jpeg align="right")

Basically, math function is used for various purposes in javascript some of which are listed below

* Math.round()
    
* Math.ceil()
    
* Math.random()
    
* Math.sqrt()
    

These above are the basic most used Math function in the real word

Let's understand them one by one with examples

### Math.round()

So Math.round() is used to get the value in rounded form. means if the value contains a decimal, it will return the integer number. Also, It will go upward and backward flow means it will return the nearest integer of the given decimal Let's see an example

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1693299130347/5c95d905-7111-4bad-8abf-482d432f103e.png align="center")

### Math.ceil()

So Math.ceil function is used to get the integer number, it is similar to Math.round() but the main difference is it gives a larger number, which is greater than or equal to a given number. Let's see an example

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1693300247858/1990135b-7593-4a0b-99e0-379af0bbd203.png align="center")

here we can clearly understand the difference in both cases it will return the higher nearest value.

### Math.random()

So this is a very commonly used function in a Js production-level environment.

Do you ever think how OTP numbers are generated ???

so the answer is Math.random() function, It will return a random number every time you hit the server. Let's see an example :

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1693300632362/ad08eefc-f0db-4b3a-81b0-b3fa143d260d.png align="center")

Here we can see that for the same line of code, We got a different output.

### Math.sqrt()

As the name suggests it will return a square root of any number.

Let's see an example

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1693300866348/ae457586-60c0-428d-a074-84bfada9e39b.png align="center")

That's all for the Math functions in JS.

If you have any query, feel free to comment.

Happy Learning:)
