Math Object Basics0%

Math Object Basics

Beginner12 min read•Updated: Jul 11, 2026
Study Materials

Math Object Basics in JavaScript

Unlike Date or Array, the Math object in JavaScript is not a constructor (you never call new Math()). It is a built-in static object containing mathematical constants and functions for rounding, geometric calculations, and numerical transformations.


1. Built-in Mathematical Constants

JavaScript
console.log(Math.PI); // 3.141592653589793 (Ratio of circumference to diameter)
console.log(Math.E); // 2.718281828459045 (Euler's constant)
console.log(Math.SQRT2); // 1.4142135623730951 (Square root of 2)

2. Rounding Functions (The Essential Four)

MethodBehaviorExampleResult
Math.round(x)Standard rounding (Rounds to nearest integer; 0.5 rounds up)Math.round(4.5)5
Math.floor(x)Always rounds DOWN toward negative infinityMath.floor(4.9)4
Math.ceil(x)Always rounds UP toward positive infinityMath.ceil(4.1)5
Math.trunc(x)Simply strips the decimal fraction (truncates)Math.trunc(-4.9)-4
JavaScript
// Comparing negative rounding:
console.log(Math.floor(-3.2)); // -4 (Down toward negative infinity)
console.log(Math.trunc(-3.2)); // -3 (Just removes .2)

3. Min, Max, and Absolute Values

A. Math.abs(x): Absolute (Non-negative) Value

JavaScript
console.log(Math.abs(-25)); // 25
console.log(Math.abs(25)); // 25

B. Math.min() and Math.max():

Finds the lowest or highest value from a list of arguments:

JavaScript
console.log(Math.min(10, 4, 88, 2, 50)); // 2
console.log(Math.max(10, 4, 88, 2, 50)); // 88
 
// Tip: Use spread operator (...) with Arrays!
const testScores = [84, 92, 78, 99, 65];
console.log(Math.max(...testScores)); // 99

4. Powers and Square Roots

JavaScript
// Power (x raised to y):
console.log(Math.pow(3, 4)); // 81 (Equivalent to 3 ** 4)
 
// Square Root:
console.log(Math.sqrt(64)); // 8
 
// Cube Root (ES6):
console.log(Math.cbrt(27)); // 3

Interactive Quiz

Practice Quiz

Question 1
What is the result of Math.floor(7.9)?
Question 2
What is the result of Math.ceil(2.1)?
Question 3
How do you find the maximum value in an array [12, 45, 9] using Math.max?
Question 4
What does Math.abs(-42) return?
Question 5
Can you instantiate the Math object with new Math()?
Next Lesson

Random Numbers Example

Continue learning with hands-on practice, examples, and exercises in the upcoming topic.

Related Lessons

Practice Quiz

Test your understanding of this lesson with 5 questions. Each question has one correct answer.

PrevNext