Math Constants: PI, E, and Others
You'll learn how to access JavaScript's built-in mathematical constants for precise scientific and geometric calculations.
What Are Math Constants?
The Math object provides several fundamental mathematical constants as properties. These are exact values (to JavaScript's floating-point precision) of important numbers used throughout mathematics, science, and engineering. Instead of manually typing approximations like 3.14159, you use these built-in constants for accuracy and readability.
The Essential Constants
JavaScript gives you these mathematical constants:
Math.PI– The ratio of a circle's circumference to its diameter (approximately 3.14159)Math.E– Euler's number, the base of natural logarithms (approximately 2.71828)Math.LN2– The natural logarithm of 2 (approximately 0.693)Math.LN10– The natural logarithm of 10 (approximately 2.302)Math.LOG2E– The base-2 logarithm of E (approximately 1.442)Math.LOG10E– The base-10 logarithm of E (approximately 0.434)Math.SQRT2– The square root of 2 (approximately 1.414)Math.SQRT1_2– The square root of 1/2 (approximately 0.707)
Using Constants in Calculations
// Calculate circle area from radius
const radius = 5;
const area = Math.PI * radius ** 2; // 78.53981633974483
// Calculate circle circumference
const circumference = 2 * Math.PI * radius; // 31.41592653589793
// Exponential growth calculations
const growth = Math.E ** 3; // 20.085536923187668
// Using SQRT2 for diagonal calculations
const squareSide = 10;
const diagonal = squareSide * Math.SQRT2; // 14.142135623730951
These constants are read-only properties—you cannot reassign them.
Key Takeaway: Use Math.PI, Math.E, and other Math constants for precise, readable mathematical calculations instead of typing approximations manually.