JavaScript Tutorial

Javascript Math

Math object provides several constants and methods to perform mathematical operation. Unlike date object, it doesn't have constructors.

Math.sqrt(n) method

This method returns the square root of the given number.

Input:-

Output:-

Math.random() method

This method returns the random number between 0 to 1.

Input:-

Output:-

Math.pow(m,n) method

This method returns the m to the power of n that is mn.

Input:-

Output:-

Math.floor(n) method

This method returns the lowest integer for the given number. For example, 3 for 3.9, 5 for 5.7.

Input:-

Output:-

Math.ceil(n) method

This method returns the largest integer for the given number. For example, 5 for 4.7, 3 for 2.9.

Input:-

Output:-

Math.round(n)  method

This method returns the rounded integer nearest for the given number. If fractional part is equal or greater than 0.5, it goes to upper value 1 otherwise lower value 0. For example – 5 for 4.9, 3 for 3.3.

Input:-

[tryjavascript_Math.round(n) method]

Output:-

Math.abs(n) method

This method returns the absolute value for the given number. For example -  4 for -4, 7.6 for -7.6.

Input:-

Output:-


Go back to Previous Course