ECMAScript 2016
JavaScript Version Numbers
The previous versions of ECMAScript were identified by numbers: ES5 and ES6.
Starting in 2016, the versions are titled according to the year they are released: ES2016, 2018, 2020, and so on.
New Features in ECMAScript 2016
This section presents the latest additions in ECMAScript 2016:
- JavaScript Exponentiation (**)
- JavaScript Exponentiation assignment (**=)
- JavaScript Array includes()
Exponentiation Operator
The exponentiation operator, marked as **
, elevates the first number by the value of the second number.
x ** y
gives the identical outcome as Math.pow(x, y)
:
Exponentiation Assignment
The exponentiation assignment operator, represented by **=
, increases the value of a variable to the power specified by the right operand.
JavaScript Array includes()
ECMAScript 2016 added the Array.includes
method to arrays.
We can determine if an item exists in an array using this method:
<!DOCTYPE html>
<html>
<body>
<h2>The ** Operator</h2>
<p id="demo"></p>
<script>
let x = 5;
let z = x ** 2;
document.getElementById("demo").innerHTML = z;
</script>
</body>
</html>
<!DOCTYPE html>
<html>
<body>
<h2>Math.pow()</h2>
<p id="demo"></p>
<script>
let x = 5;
let z = Math.pow(x, 2)
document.getElementById("demo").innerHTML = z;
</script>
</body>
</html>
<!DOCTYPE html>
<html>
<body>
<h2>Exponentiation Assignment (**=)</h2>
<p id="demo"></p>
<script>
let x = 5;
x **= 2;
document.getElementById("demo").innerHTML = x;
</script>
</body>
</html>
<!DOCTYPE html>
<html>
<body>
<h1>JavaScript Arrays</h1>
<h2>The includes() Method</h2>
<p>Check if the fruit array contains "Mango":</p>
<p id="demo"></p>
<p>
<strong>Note:</strong> The includes method is not supported in Edge 13 (and earlier versions).
</p>
<script>
const fruits = ["Banana", "Orange", "Apple", "Mango"];
document.getElementById("demo").innerHTML = fruits.includes("Mango");
</script>
</body>
</html>