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.LOG2EThis 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
logValueand set it toMath.LOG2E. - We log
logValueto 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
xand set it toMath.E. - We calculate the base-2 logarithm of
xusingMath.LOG2E. - The result is stored in the variable
logResult. - We log
logResultto 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
aandbrepresenting two numbers. - We calculate the base-2 logarithm of the quotient of
aandbusing the formulaMath.log2(a / b). - The result is stored in the variable
logQuotient. - We log
logQuotientto 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.