JavaScript Math

JavaScript Math

JavaScript provides a built-in Math object that allows you to perform mathematical operations, such as rounding numbers, generating random numbers, trigonometry functions, powers, square roots, and more.

The Math object works without creating an instance, meaning you use it directly:


Common Math Properties

Property Description Example
Math.PI Value of π (Pi) console.log(Math.PI); // 3.141592653589793
Math.E Euler’s number console.log(Math.E);
Math.SQRT2 Square root of 2 console.log(Math.SQRT2);

Math Methods

1. Rounding Numbers


2. Power and Square Root


3. Absolute Value


4. Min and Max


5. Random Numbers


6. Trigonometry


Examples

✔ Calculate Circle Area

✔ Generate a Random OTP (4-digit)


Summary

Category Example
Rounding Math.round(), Math.ceil(), Math.floor()
Random Math.random()
Power Math.pow(), Math.sqrt()
Values Math.PI, Math.E

CodeCapsule

Sanjit Sinha — Web Developer | PHP • Laravel • CodeIgniter • MySQL • Bootstrap Founder, CodeCapsule — Student projects & practical coding guides. Email: info@codecapsule.in • Website: CodeCapsule.in

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *