Course contentsShow
← JavaScript
Lesson 144 of 2,7234. Working with NumbersFree lesson

Math Constants: PI, E, and Others

Accessing mathematical constants like Math.PI and Math.E for precise calculations.

Math Constants: PI, E, and Others

You'll learn how to access precise mathematical constants that JavaScript provides for accurate calculations.

What Are Math Constants?

When you need precise mathematical values like π (pi) or e (Euler's number), typing 3.14 or 2.71 isn't accurate enough for serious calculations. JavaScript provides these values as properties on the Math object with full precision, so you don't have to memorize or estimate them.

Think of the Math object as a toolbox. Earlier you learned about the tools inside (methods like Math.sqrt or Math.round). Now you're learning about the reference values stored in that same toolbox—constants that never change but are always there when you need them.

The Key Constants

Math.PI

The ratio of a circle's circumference to its diameter (~3.14159...). Use this for circle calculations:

const radius = 5;
const circumference = 2 * Math.PI * radius;  // ~31.4159
const area = Math.PI * radius * radius;       // ~78.5398

Math.E

Euler's number (~2.71828...), the base of natural logarithms. Essential for exponential growth calculations:

const result = Math.E * 2;  // ~5.43656

Other Constants

  • Math.LN2: Natural logarithm of 2 (~0.693)
  • Math.LN10: Natural logarithm of 10 (~2.303)
  • Math.LOG2E: Base-2 logarithm of e (~1.443)
  • Math.LOG10E: Base-10 logarithm of e (~0.434)
  • Math.SQRT2: Square root of 2 (~1.414)
  • Math.SQRT1_2: Square root of 1/2 (~0.707)

These constants are read-only—you can't change them (which makes sense for mathematical truths!).

Key Takeaway: Use Math.PI, Math.E, and other Math constants for precise mathematical values instead of approximating them yourself.