JavaScript Math LOG2E Property



In JavaScript, the Math.LOG2E property represents the base 2 logarithm of Euler's number, denoted as "e". Euler's number, often represented by the mathematical constant "e" approximately equals 2.71828.

The LOG2E property's value is a numeric constant, approximately equal to 1.44269. This value is derived from the mathematical relationship between the natural logarithm of "e" (denoted as "ln(e)") and the base 2 logarithm of "e".

Mathematically, the relationship between the base 2 logarithm of "e" and "ln(e)" can be expressed as −

log2(e) = ln(e) / ln(2)

So, Math.LOG2E is the value of ln(e) divided by the value of ln(2).

Syntax

Following is the syntax of JavaScript Math.LOG2E property −

Math.LOG2E

Return value

This property returns a number that represents the base-2 logarithm of E.

Example 1

In the following example, we are using the JavaScript Math.LOG2E property to retrieve the base-2 logarithm of E −

<html>
<body>
<script>
   let result = Math.LOG2E;
   document.write(result);
</script>
</body>
</html>

Output

If we execute the above program, it returns a value approximately 1.44269.

Example 2

Here, we are comparing the value "1.4426950408889634" with Math.LOG2E property −

<html>
<body>
<script>
   let result = Math.LOG2E;
   document.write(result === 1.4426950408889634);
</script>
</body>
</html>

Output

It returns true because, this property represents the value 1.4426 (which is the base-2 logarithm of E).

Advertisements