Free Web Development Online Tutorials, Learn to Code
Learn JavaScript, Free JavaScript Tutorial for Beginners, Interactive JavaScript Examples

javascript math function examples

How to use JavaScript built-in Math Methods

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

Math.round() in Javascript

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

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:

Math.pow(),Math.sqrt() in Javascript
Math.pow(x, y) returns the value of x to the power of y AND Math.sqrt(x) returns the square root value of x:


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

If you keep on refreshing this page the random number will also keep on changing on this page, try refresh

Math.max() and Math.min()

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


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