LoginSignup
3
1

More than 5 years have passed since last update.

あと1ヶ月で2016年も終わるので、ES2016をおさらい。

Posted at

classやアロー関数の登場したES2015に比べて、ES2016は地味な感じがします。
しかし、2017年になる前にもう一度ES2016を振り返ってみましょう!

Array.prototype.includes

これはArray.prototype.indexOfみたいな感じで、配列の中の要素を確認できます。
indexOfとの違いは値があればtrue、なければfalseを返す所です。

すっきり書くことができます。

const items = [1, 2, 3, 4, 5];

// Array.prototype.indexOf
if (items.indexOf(4) !== -1) {
  console.log(items.indexOf(4)); // 3
}

// Array.prototype.includes
if (items.includes(4)) {
  console.log(items.includes(4)); // true
}

Exponentiation Operator

累乗計算に使用するMatn.pow()が簡単に書けるようになりました。

Math.pow(4, 2); // 16
4 ** 2 //16

let count = 3; 
count **= count; // 27

・・・以上です。

まとめ

promiseやgenerator関数に関する仕様の変更はあったみたいですが、ES2016で追加された機能はこれだけみたいです。
個人的には、今後await/asyncなど実用的な機能が追加されるのでそっちのほうが楽しみです。

3
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
1