tamilz
1 min readFeb 1, 2024

Math built in function javascript

JavaScript provides a built-in Math object that includes various mathematical functions and constants. Here are some commonly used Math functions in JavaScript:

  1. Math.round(x):
  • Rounds a number to the nearest integer.
  • Example: Math.round(1.2) returns 1, and Math.round(1.7) returns 2

2.Math.ceil(x):

  • Rounds a number upward to the nearest integer (ceiling).
  • Example: Math.ceil(1.2) returns 2, and Math.ceil(1.7) returns 2.

3.Math.floor(x):

  • Rounds a number downward to the nearest integer (floor).
  • Example: Math.floor(1.2) returns 1, and Math.floor(1.7) returns 1.

4.Math.abs(x):

  • Returns the absolute value of a number.
  • Example: Math.abs(-5) returns 5.

5.Math.sqrt(x):

  • Returns the square root of a number.
  • Example: Math.sqrt(9) returns 3.

6.Math.pow(x, y):

  • Returns the value of x raised to the power of y.
  • Example: Math.pow(2, 3) returns 8 (2^3).

7.Math.min(x1, x2, …, xn):

  • Returns the smallest of the provided numbers.
  • Example: Math.min(5, 3, 7) returns 3.

8.Math.max(x1, x2, …, xn):

  • Returns the largest of the provided numbers.
  • Example: Math.max(5, 3, 7) returns 7.

9.Math.random():

  • Returns a random floating-point number between 0 (inclusive) and 1 (exclusive).
  • Example: Math.random() returns a value between 0 (inclusive) and 1 (exclusive).

10.Math.PI:

  • Represents the mathematical constant Pi (π).
  • Example: Math.PI returns approximately 3.141592653589793.

11.Math.Expression:

  • Represents the mathematical constant e.
  • Example: Math.E returns approximately 2.718281828459045.

These are just a few examples of the functions provided by the Math object in JavaScript. They are often used for various mathematical calculations in web development.

No responses yet