JavaScript Math Object
Math in JavaScript is a top-level, pre-defined object that has properties and methods for mathematical constants and functions. For example, Math object’s PI property contains the value of pi.
The properties of Math object represent mathematical constants and its methods are mathematical functions. JavaScript Math object provides several constants and methods for performing mathematical calculations.
We do not need to create an object or instance of Math because it doesn’t have constructors to create objects. This is because the JavaScript Math object is a static object, so we don’t need to instantiate it.
All constants and functions of Math are static. Therefore, it exits automatically in any JavaScript program.
Syntax to Access Elements of Math Object
To access the properties and functions of Math object, we do not need to create an instance. We can access properties and functions of JavaScript Math, as usual, by placing a dot after the object name (Math) and writing the property or function name. The general syntax to access them is as follows:
Math.property_name;
Math.function_name();
For example:
var pi = Math.PI;
var p = Math.pow();
Static Properties of JavaScript Math object
All the properties refer to constants that do not change. Therefore, these properties are read-only properties. Math object in JavaScript provides several properties that represent a valuable constant values in math. The most common properties of math object are as:
(a) Math.E: It is Euler’s constant and the base of natural logarithms. It is a very important constant in mathematics. Its approximate value is 2.718281828459045.
It returns Ex where x is an argument value, and E is Euler’s constant. Let’s take an example based on it.
<script>
let x = Math.E;
let y = 10;
console.log("Value of E = " +x);
let z = x^y + 10;
console.log(z);
</script>
Output:
Value of E = 2.718281828459045
22
(b) Math.LN2: It is the natural logarithm of 2, approximate value o.693. Let’s take an example.
<script>
let x = Math.LN2;
console.log("Value of x = " +x);
let y = (x + 10) / x;
console.log("Value of y = " +y);
</script>
Output:
Value of x = 0.693
Value of y = 15.426
(c) Math.LN10: It is a natural logarithm of 10, approximate value 2.302. Let’s take an example based on this math object property.
<script>
let x = Math.LN10;
console.log("Value of x = " +x);
let y = (x + 10) * 2 / 10;
console.log("Value of y = " +y);
</script>
Output:
Value of x = 2.302
Value of y = 2.460
(d) Math.LOG2E: Another important constant in math is base-2 logarithm of Euler’s constant. Its approximate value is 1.442. Let’s take an example based on this property.
(e) Math..LOG10E: It is a base-10 logarithm of Euler’s constant. Its approximate value is 0.434.
(f) Math.PI: It returns the value of pi, that is the ratio of circumference of a circle to its diameter. Its approximate value is 3.14. Let’s take an example in which we will calculate the circumference and area of circle.
<script>
let x = Math.PI;
// Create a function to find the circumference of circle.
function calCircum(r) {
let circum = 2 * x * r;
console.log("Circumference of circle = "+circum);
}
// Create a function to find the area of circle.
function calArea(r) {
let area = x * r * r;
console.log("Area of circle: " +area);
}
// Calling functions with passing arguments.
calCircum(5);
calArea(5);
</script>
Output:
Circumference of circle = 31.41592653589793
Area of circle: 78.53981633974483
(g) Math.SQRT2: It is a square root of 2 that is a well-known constant in mathematics. Its approximate value is 1.414. Let’s take an example based on this constant.
<script>
let x = Math.SQRT2;
console.log("Value of x = "+x);
let y = x * 10 / 10 + 10;
console.log("Value of y = "+y);
</script>
Output:
Value of x = 1.414
Value of y = 11.414
(h) Math.SQRT1_2: It is the square root of 0.5, whose approximate value is 0.707.
Static Methods of Math object
We can divide the methods of Math object in JavaScript into four categories. Each one is related to a distinct branch of mathematics. They are:
- Trigonometry methods
- Integer methods
- Logarithmic, Exponential, Power, Root methods
- Miscellaneous methods
JavaScript specified all methods of Math object in lowercase letters, opposite to constants, which are specified in uppercase letters. So. let’s understand them one by one with the help of examples.



