Math Object in JavaScript

Math Object in JavaScript

In our previous tutorial, we created a simple calculator using JavaScript. In this tutorial, you will learn advanced Math functions to perform scientific operations of the calculator using JavaScript. To perform mathematical tasks on web pages, we use JavaScript Math object. This object allows us to perform different mathematical work and calculation by using just one simple function.

Math Functions

In JavaScript there are sevral mathematical function some are given below:

  • Random()
  • Max()
  • Min()
  • Floor()
  • Round()
  • Abs()
  • Log()
  • Cos()
  • Sin()
  • Tan()
  • Sqrt()

Math.random()

This function returns 1 or 0 randomly.

Result

Math.Max()

This function returns maximum value from its given parameters.

Result

Math.Min()

This function returns minimum value from its given parameters.

Result

Math.floor()

This function rounds a number down to the nearest integer.

Result

Math.Round()

This function rounds a number to the nearest integer.

Result

Math.ceil()

This function rounds a number up to the nearest integer.

Result

 

Math.Abs()

This function returns the absolute value of given parameter.

Result

Math.log()

This function returns the log of the given parameter.

Result

Math.tan()

This function returns the tangent of the given parameter.

Result

Math.sin()

This function returns the sin of the given parameter.

Result

Math.cos()

This function returns the cos of the given parameter.

Result

Math.sqrt()

This function returns the square of the given parameter.

Result

JavaScript Math Object Live Demo