JavaScript Math.LN2 Property
- Syntax of JavaScript
Math.LN2: - Example Code: Use the
Math.LN2Property to Find the Natural Logarithm of 2 - Example Code: Use the
Math.LN2Property as a Default Parameter of a Function
In JavaScript, the Math.LN2 property is a built-in Math library method. Programmers use it to find the natural logarithm (Base E) of 2, which is 0.693 and always remains constant.
Syntax of JavaScript Math.LN2:
let output = Math.LN2; Parameters
This method doesn’t take any parameter values.
Return
The Math.LN2 property returns the natural logarithm of 2, which is approximately 0.693.
Example Code: Use the Math.LN2 Property to Find the Natural Logarithm of 2
We have used the Math.LN2 method to find the natural logarithm of the 2 in the example below. In the output below, you can see that it returns the 0.693 value.
let output = Math.LN2; console.log(output); Output:
0.6931471805599453 Example Code: Use the Math.LN2 Property as a Default Parameter of a Function
In this example, we have created the function and passed the value of the Math.LN2 property as a default parameter value. The function func returns the multiplication of the first and second arguments, and here, the second argument is the value of Math.LN2.
function func(value1, value2=Math.LN2){ return value1*value2; } let output1 = func(10) console.log(output1); console.log(func(2.32)); console.log(func(0.000032)); Output:
6.931471805599453 1.608101458899073 0.000022180709777918248 The Math.LN2 property always returns the constant value, the natural logarithm of 2 that we have seen in this article.
