Skip to content

Latest commit

 

History

History
32 lines (22 loc) · 789 Bytes

File metadata and controls

32 lines (22 loc) · 789 Bytes

ES2016

ECMAScript 2016 ,于 2016 年 6 月完成。

与 ES2015 相比,ES2016 是 JavaScript 的一个小版本,仅包含两个功能:

  • Array.prototype.includes
  • 求幂运算符

Array.prototype.includes()

此功能引入了更易读的语法,用于检查数组是否包含元素。而在之前需要使用 indexOf 检查数组中的索引来判断,如果元素不存在则返回 -1。

// ES2015
if ([1, 2].indexOf(3) === -1) {
  console.log('Not found')
}

// ES2016
if (![1, 2].includes(3)) {
  console.log('Not found')
}

求幂运算符(**)

求幂运算符 ** 相当于 Math.pow(),而被直接引入语言本身,对于数学密集型的 JavaScript 应用程序来说是一个很好的补充。

Math.pow(4, 2) === 4 ** 2 // 4*4