4

Why is there a a property in Javascript that returns the approximate square root of 2. Isn't Math.sqrt(2) enough? There is also a property that returns the square root of 0.5.

I'm wondering out of pure curiosity.

u840903
  • 2,151
  • 2
  • 16
  • 27

3 Answers3

6

This is a constant used in many math equations. Since it is a constant it doesn't need to be calculated each time it's used, and it has high precision.

Winger
  • 676
  • 3
  • 7
3

Convience factor, as seen here, it is actually a widely used constant.

Mike Lewis
  • 63,433
  • 20
  • 141
  • 111
0

Some values are used often enough that it's faster to store them as constants than to recompute them. The square roots of 2 and 0.5 are two such constants.

Gabe
  • 84,912
  • 12
  • 139
  • 238