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

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

  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:

  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:

  5. Math.random()

    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

  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.

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

  8. Math.abs()

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

  9. Math.cos()

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

  10. Math.tan()

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

  11. Math.sin()

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

  12. Math.log()

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


If you want to learn more about javascript math function, here are some excellent sites that can help you to fall in love math.

JavaScript programming tutorials to learn JavaScript coding step by step, develop website using JavaScript and html.
Advanced JavaScript
JavaScript Math Function
javascript Interview Questions Answers
JavaScript Examples | JavaScript Online Course