ES6
ES6
參考資料:(https://developer.mozilla.org/zh-TW/docs/Web/JavaScript/Reference/Functions/Arrow_functions)
參考資料:(http://www.cnblogs.com/liuning8023/p/4911139.html)
參考資料:(https://developer.mozilla.org/zh-TW/docs/Web/JavaScript/Reference/Functions/Arrow_functions)
let const
參考資料:(https://ithelp.ithome.com.tw/articles/10185142)
撰寫風格建議
根據Airbnb的JavaScript風格指引,以及最近改版的Google JavaScript風格指引,以下總結幾點對於let或const在使用上,幾個建議的採用的撰寫風格:
不要再用var來宣告變數,改用let與const,而且優先使用const,除非需要再指定值才用let。(Google 5.1.1, Airbnb 2.1/2.2) 不要使用逗號(,)在同一行來定義(宣告)多個變數或常數,例如let a = 1, b = 2是不必要的,應該是一行一個定義(宣告)。(Google 5.1.2, Airbnb 13.2) 並不是在區塊中或函式中區域的最上面來宣告變數/常數,而是在合理的位置,在變數/常數首次被使用時的上面一行來宣告變數。(Google 5.1.3, Airbnb 13.4)
array.includes()
參考資料:(https://dev.to/adroitcoder/includes-vs-indexof-in-javascript)
類似IndexOf()
可以比較 NaN 和 undefined
回傳值是bool
Last updated