箭頭函式為ES6的新增語法
例 ❶ (答案:72)
const numA = (x,y) => {
const a = 3;
return a * x * y;
console.log(numA(4,6));
例 ❶ (答案:24)
const numA = (x,y) => {
return `答案是${ x * y}`;
}
console.log(numA(4, 6));
縮寫成 ??
const numC = (x,y) => `答案是${ x * y}`;
console.log(numC(4, 6));
例 ❷
const data = [1, 2, 45, 83];
const newData = data.map(function (item) {
return item + 2;
})
縮寫成 ??
const data = [1, 2, 45, 83];
const newData = data.map((item) => item + 2);
也可以這樣寫