ECMAScript 2016

JavaScript naming conventions started with ES1, ES2, ES3, ES5, and ES6.

However, ECMAScript 2016 and 2017 are not called ES7 and ES8.

Since 2016, new versions have been named by year (ECMAScript 2016/2017/2018).

New features in ECMAScript 2016

This chapter introduces the new features of ECMAScript 2016:

  • JavaScript exponent (**)
  • JavaScript exponent assignment (**=)
  • JavaScript Array.prototype.includes

Exponentiation operator

Exponentiation operator (**) Raise the first operand to the power of the second operand.

ຄວາມຄົງຄວາມຈິງ

let x = 5;
let z = x ** 2;          // The result is: 25

ພະຍາຍາມດີຕະຫຼອດ

x ** y Generates the same result as Math.pow(x, y) The same result:

ຄວາມຄົງຄວາມຈິງ

let x = 5;
let z = Math.pow(x, 2);   // The result is: 25

ພະຍາຍາມດີຕະຫຼອດ

Exponent assignment

Exponent assignment operator (**=) Increase the value of the variable to the power of the right operand.

ຄວາມຄົງຄວາມຈິງ

let x = 5;
x **= 2; // The result is 25

ພະຍາຍາມດີຕະຫຼອດ

Chrome 52 and Edge 14 are the first browsers to fully support the exponentiation operator:

Chrome IE Firefox Safari Opera
Chrome 52 Edge 14 Firefox 52 Safari 10.1 Opera 39
2016 年 7 月 ເດືອນສິງຫາ 2016 2017 年 3 月 2017 年 3 月 ເດືອນສິງຫາ 2016

JavaScript Array.includes()

ECMAScript 2016 将 Array.prototype.includes 引入数组。这允许我们检查元素是否存在于数组中:

ຄວາມຄົງຄວາມຈິງ

const fruits = ["Banana", "Orange", "Apple", "Mango"];
fruits.includes("Mango"); // ມີຄວາມຈິງ

ພະຍາຍາມດີຕະຫຼອດ

ທຸກການສະແດງສາຍທີ່ຫຼິ້ນໃນການຄົ້ນຫາເກມອກ Array.prototype.includes:

Chrome IE Firefox Safari Opera
Chrome 47 Edge 14 Firefox 43 Safari 9 Opera 34
ເດືອນທັນວາ 2015 ເດືອນສິງຫາ 2016 ເດືອນທັນວາ 2015 ເດືອນຕຸລາ 2015 ເດືອນທັນວາ 2015