JavaScript Math LOG2E
Syntax & Examples
Math.LOG2E static-property
The Math.LOG2E property represents the base-2 logarithm of Euler's number (E), which is approximately equal to 1.443.
Syntax of Math.LOG2E
The syntax of Math.LOG2E static-property is:
Math.LOG2E
This LOG2E static-property of Math base-2 logarithm of E; approximately 1.443.
✐ Examples
1 Using Math.LOG2E to calculate logarithmic values
In JavaScript, we can use the Math.LOG2E
property to assist in base-2 logarithm calculations.
For example,
- We create a variable
logValue
and set it toMath.LOG2E
. - We log
logValue
to the console using theconsole.log()
method.
JavaScript Program
const logValue = Math.LOG2E;
console.log(logValue);
Output
1.4426950408889634
2 Using Math.LOG2E in a logarithmic expression
In JavaScript, we can use the Math.LOG2E
property in logarithmic expressions.
For example,
- We create a variable
x
and set it toMath.E
. - We calculate the base-2 logarithm of
x
usingMath.LOG2E
. - The result is stored in the variable
logResult
. - We log
logResult
to the console using theconsole.log()
method.
JavaScript Program
const x = Math.E;
const logResult = Math.LOG2E;
console.log(logResult);
Output
1.4426950408889634
3 Using Math.LOG2E in a mathematical formula
In JavaScript, we can use the Math.LOG2E
property in various mathematical formulas involving logarithms.
For example,
- We create variables
a
andb
representing two numbers. - We calculate the base-2 logarithm of the quotient of
a
andb
using the formulaMath.log2(a / b)
. - The result is stored in the variable
logQuotient
. - We log
logQuotient
to the console using theconsole.log()
method.
JavaScript Program
const a = 8;
const b = 2;
const logQuotient = Math.log2(a / b);
console.log(logQuotient);
Output
2
Summary
In this JavaScript tutorial, we learned about LOG2E static-property of Math: the syntax and few working examples with output and detailed explanation for each example.