The JavaScript math object provides several constants and methods to perform mathematical operation. Unlike date object, it doesn't have constructors.
The JavaScript math.sqrt(n) method returns the square root of the given number.
See this example:
Output:
The JavaScript math.random() method returns the random number between 0 to 1.
See this example:
Output:
The JavaScript math.pow(m,n) method returns the m to the power of n that is mn.
See this example:
Output:
The JavaScript math.floor(n) method returns the lowest integer for the given number. For example 3 for 3.7, 5 for 5.9 etc.
See this example:
Output:
The JavaScript math.ceil(n) method returns the largest integer for the given number. For example 4 for 3.7, 6 for 5.9 etc.
See this example:
Output:
The JavaScript math.round(n) 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 4 for 3.7, 3 for 3.3, 6 for 5.9 etc.
See this example:
Output:
The JavaScript math.abs(n) method returns the absolute value for the given number. For example 4 for -4, 6.6 for -6.6 etc.
See this example:
Output: