ES7求幂运算

31 阅读1分钟

Date: 2018-10-22

ES7只新增了2个新特性

  • Array.prototype.includes
  • Exponentiation Operator(求幂运算)

本文只讲解ES7求幂运算,includes方法请移步ES7 includes

在ES6中,可以使用Math.pow来实现求幂运算

Math.pow(2, 3); // 8
Math.pow(3, 2); // 9

ES7中,可以使用**来实习求幂运算

2 ** 3 // 8
3 ** 2 // 9