Javascript Tips #2 : Using Mathematical Constants In Javascript
Note down following thing -
- The Math object allows you to perform mathematical tasks.
- We can access JavaScript Object and its methods to access the mathematical constants.
We can Access Following Properties
Property | Description | Value(Approx) |
---|---|---|
E | Euler's number | 2.718 |
LN2 | Natural logarithm of 2 | 0.693 |
LN10 | Natural logarithm of 10 | 2.302 |
LOG2E | Base-2 logarithm of E | 1.442 |
LOG10E | Base-10 logarithm of E | 0.434 |
PI | PI | 3.14 |
SQRT1_2 | Square root of 1/2 | 0.707 |
SQRT2 | Square root of 2 | 1.414 |
Sample Program :
<script language="JavaScript"> <!-- var radius; radius = 3; document.write(Math.PI * ((radius)*(radius))); // --> </script>