JavaScript Math LN2
Syntax & Examples
Math.LN2 static-property
The Math.LN2 property represents the natural logarithm of 2, which is approximately equal to 0.693.
Syntax of Math.LN2
The syntax of Math.LN2 static-property is:
Math.LN2
This LN2 static-property of Math natural logarithm of 2; approximately 0.693.
✐ Examples
1 Using Math.LN2 to calculate a natural logarithm
In JavaScript, we can use the Math.LN2
property to obtain the natural logarithm of 2.
For example,
- We create a variable
logValue
and set it toMath.LN2
. - We log
logValue
to the console using theconsole.log()
method.
JavaScript Program
const logValue = Math.LN2;
console.log(logValue);
Output
0.6931471805599453
2 Using Math.LN2 in a logarithmic expression
In JavaScript, we can use the Math.LN2
property in logarithmic expressions to simplify calculations.
For example,
- We create a variable
x
and set it to 2. - We calculate the natural logarithm of
x
usingMath.log(x)
. - We verify the result by comparing it with
Math.LN2
. - We log both values to the console using the
console.log()
method.
JavaScript Program
const x = 2;
const logX = Math.log(x);
console.log(logX, Math.LN2);
Output
0.6931471805599453 0.6931471805599453
3 Using Math.LN2 in exponential decay calculations
In JavaScript, we can use the Math.LN2
property in exponential decay calculations to determine the half-life of a substance.
For example,
- We create variables
initialAmount
andtime
representing the initial amount of a substance and the time elapsed. - We calculate the remaining amount of the substance using the formula
initialAmount * Math.exp(-time * Math.LN2)
. - The result is stored in the variable
remainingAmount
. - We log
remainingAmount
to the console using theconsole.log()
method.
JavaScript Program
const initialAmount = 100;
const time = 1;
const remainingAmount = initialAmount * Math.exp(-time * Math.LN2);
console.log(remainingAmount);
Output
50
Summary
In this JavaScript tutorial, we learned about LN2 static-property of Math: the syntax and few working examples with output and detailed explanation for each example.