---
# System prepended metadata

title: "\U0001F3C5 Day 14 - 箭頭函式"
tags: [Vue 直播班 - 2022 冬季班]

---

---
tags: Vue 直播班 - 2022 冬季班
---
# 🏅 Day 14 - 箭頭函式

參考文章: https://wcc723.github.io/javascript/2017/12/21/javascript-es6-arrow-function/

### 教學

箭頭函式的運用技巧如下：
```js=
// 傳統函式
function saySomething(string) {
  return '接招' + string; 
}

// 轉成箭頭函式
const saySomething = (string) => {
  return '接招 ' + string;
}
```
```js=
// 當只有單行表達式時，可同時省略 return 及 {}
// 省略後依然保有回傳的特質
const saySomething = (string) => '接招 ' + string;
console.log(saySomething('菜鳥!'));

// 不過要注意，如果有使用 {}，就需要自行加上 return
const saySomething = (string) => {'接招 ' + string};
console.log(saySomething('菜鳥!')); // 會回傳 undefined
```

```js=
// 只有一個參數可以不加括號 ()
const saySomething = string => '接招 ' + string;
console.log(saySomething('菜鳥!'));

// 沒有參數、參數有兩個以上都不能省略 ()
const saySomething = () => '接招 菜鳥!';
console.log(saySomething());
```

題目
---
請將以下程式碼簡化為箭頭函式 (不影響結果的情況下進行最大簡化)

```js=
// 題目一
function sum(a, b) {
  let c = a + b;
  return c;
}
console.log(sum(5, 6));

// 題目二
function square(num) {
  return num * num;
}
console.log(square(5))

// 題目三
setTimeout(function() {
  console.log('延遲 1 秒');
}, 1000);

// 題目四
let arr = [1, 2, 3];
let arrNew = arr.map(function(item, i) {
  return item * i;
});
console.log(arrNew);

// 題目五
let obj = {
  fn: function fn2(a) {
    return a * a;
  }
}
console.log(obj.fn(10));
```


## 回報流程

將答案寫在 CodePen 並複製 CodePen 連結貼至底下回報就算完成了喔! 
解答位置請參考下圖（需打開程式碼的部分觀看）

![](https://i.imgur.com/vftL5i0.png)

<!-- 解答：  
// 題目一
const sum = (a, b) => {
  let c = a + b;
  return c;
}
console.log(sum(5, 6));

// 題目二
let square = num => num * num;
console.log(square(5));

// 題目三
setTimeout(() => console.log('延遲 1 秒'), 1000);

// 題目四
let arr = [1, 2, 3];
let arrNew = arr.map((item, i) => item * i);
console.log(arrNew);

// 題目五
let obj = {
  fn: a => a * a
}
console.log(obj.fn(10));
-->




回報區
---


|     Discord     |                                CodePen / 答案                                |
|:---------------:|:----------------------------------------------------------------------------:|
|    Kimi#9564    |              [CodePen](https://codepen.io/kimihu91/pen/xxJwjGm)              |
|   Wendy3#5615   |              [Codepen](https://codepen.io/wendy03/pen/NWBxQbr)               |
|     bakiii      |               [codepen](https://codepen.io/aki168/pen/yLqygXp)               |
|    WeiJ#7376    |               [CodePen](https://codepen.io/weij0/pen/zYLrgNj)                |
|    冬天#5215    |              [codepen](https://codepen.io/winter_/pen/eYjJqgy)               |
|    阿榮#8277    |        [CodePen](https://codepen.io/mogzbvfl-the-reactor/pen/jOpWgVy)        |
|  LinaChen#1796  |              [CodePen](https://codepen.io/LinaChen/pen/yLqemgo)              |
|   popeye#5081   |             [codepen](https://codepen.io/popeye_ux/pen/mdjVNRb)              |
|     YC#2522     |                [CodePen](https://codepen.io/YCLu/pen/oNMjqYy)                |
|    威0#6919     |      [codepen](https://codepen.io/n0918679182/pen/eYjJqEV?editors=0012)      |
| PeihanWang#2530 |      [CodePen](https://codepen.io/PeihanWang/pen/vYaLogq?editors=0012)       |
|    ㄚ翔#8126    |    [codepen](https://codepen.io/engineerjohnson/pen/abjdeya?editors=1111)    |
|    yuyu#6310    |       [codepen](https://codepen.io/yuyu0905/pen/VwBeoWO?editors=0012)        |
|  AuroraC#6539   |        [codepen](https://codepen.io/AuroraC/pen/ExpPqmp?editors=0012)        |
|  ChloeLo#4858   |              [codepen](https://codepen.io/chloelo/pen/MWBKNmE)               |
| suihsilan#9485  |       [codepen](https://codepen.io/suihsilan/pen/jOpWgGm?editors=0010)       |
|     PH#2731     |       [codepen](https://codepen.io/lokf9527/pen/yLqemoz?editors=0010)        |
|  kenki100#0068  |               [Codepen](https://codepen.io/ken100/pen/RwBrXZb)               |
|    RJRS#9430    |                [CodePen](https://codepen.io/RJRS/pen/xxJZvjm)                |
|   albee#9121    |      [Codepen](https://codepen.io/albee-chang/pen/OJwMKEX?editors=1112)      |
|    Alex#9978    | [Codepen](https://codepen.io/datsxzqg-the-selector/pen/yLqempP?editors=0011) |
|     JY#5712     |              [CodePen](https://codepen.io/judy_123/pen/VwBeozO)              |
|    泊岸#3466    |      [CodePen](https://codepen.io/qoq77416416/pen/LYBGwmv?editors=0012)      |
|   JackC#0411    |              [CodePen](https://codepen.io/key0329/pen/WNKrVWZ)               |
| christina#6185  |             [Codepen](https://codepen.io/chrisc0210/pen/NWBxQVv)             |
|    Chi#7605     |              [Codepen](https://codepen.io/YoChi84/pen/poZgMYL)               |
|    Tami#6742    |         [Codepen](https://codepen.io/wqsdqbjn-the-vuer/pen/zYLrgMM)          |
|  mandylai#4055  |            [Codepen](https://codepen.io/mandy-lai-2/pen/vYaLooL)             |
|   Hilda#7085    |         [Codepen](https://codepen.io/vwquikad-the-vuer/pen/RwBrXvW)          |
|    威爾#1694    |              [CodePen](https://codepen.io/WILL_Wu/pen/NWBNKGX)               |
|yaru#6308|[CodePen](https://codepen.io/lszaietc/pen/YzjqKPw?editors=0011)|
|Eileen#6454|[CodePen](https://codepen.io/Eileen-io/pen/zYLqOGX)|
|大頭#8116|[CodePen](https://codepen.io/d22495521/pen/rNreBVP?editors=1012)|
|Jill Lee#0809|[Codepen](https://codepen.io/chi-ling-lee/pen/WNKwewM?editors=0011)|
|RT#2151|[Codepen](https://codepen.io/youtingluo/pen/RwBabKK?editors=0011)|
|圈圈#4060|[Codepen](https://codepen.io/wjejfczn-the-bold/pen/GRBZKEE?editors=1111)|
|米米#1824|[Codepen](https://codepen.io/Jameshsu0407/pen/jOpqNBp?editors=0011)|
|小夜#3809|[Codepen](https://codepen.io/Naito_K/pen/mdjVNNE?editors=0011)|
|Potatolee#7749|[Codepen](https://codepen.io/potatoleee/pen/VwBaZMK?editors=1011)|
|int#7518|[Codepen](https://codepen.io/intHuang/pen/ExpKYLa?editors=0011)|
|Winnie#1306|[Codepen](https://codepen.io/WinnieWuWinnie/pen/mdjPbLM?editors=0012)|
|Fang#4680|[Codepen](https://codepen.io/std95174/pen/KKBzPxJ)
|jimmyFang#9575|[Codepen](https://codepen.io/pohxiqqo/pen/zYLqOeG?editors=0011)|
|魚子醬#5220|[Codepen](https://codepen.io/haihsuan/pen/vYaGBPe)|
|RainLiao#2616|[Codepen](https://codepen.io/billpop741/pen/NWBNKvM)|
|masterYan#2480|[Codepen](https://codepen.io/htzwgoqt-the-looper/pen/PoBNoZd?editors=1010)|
|大衛#4869|[Codepen](https://codepen.io/exnsrpjc/pen/XWBdrmG)|
|柚子#3958|[Codepen](https://codepen.io/as6625998/pen/ExpKxNN?editors=1011)|
|Ruby Chen#7452|[Codepen](https://codepen.io/ruby92429/pen/BaPKaQv?editors=0012)|
|黑白兔#0684|[Codepen](https://codepen.io/johnny329/pen/BaPKBvV)|
|Rena#6249|[Codepen](https://codepen.io/aureate0116/pen/jOpqOjq)|
|RyanC#6960|[Codepen](https://codepen.io/RyanYD/pen/wvxGBvB?editors=0011)|
|LHchien33#6232|[Codepen](https://codepen.io/lin_chien/pen/PoBNweN)|
|無名#6427|[Codepen](https://codepen.io/Nomoney/pen/GRBpxMa)|
|Mylène#2481|[CodePen](https://codepen.io/hamajibashi/pen/KKBzwyq)|
|法希娜#3206|[CodePen](https://codepen.io/yiiserpf-the-encoder/pen/VwBaYgw?editors=1011)|
|Cheryl#4007|[Codepen](https://codepen.io/Cheryl-Hsu/pen/BaPKyEW?editors=0012)|
|RainJ#3480|[Codepen](https://codepen.io/RainJCode/pen/RwBaPYZ)|
|KC_8685#9343|[Codepen](https://codepen.io/cathy7411/pen/KKBzpeb)|
|CatBoxy#4207|[Codepen](https://codepen.io/nekoboxy/pen/VwBaYjR)|
|Benson#6763|[CodePen](https://codepen.io/kumashow/pen/qByZObm)|
|Sean#3825|[CodePen](https://codepen.io/sean_1215/pen/gOjrYye?editors=0011)|
|出事了阿伯#9923|[CodePen](https://codepen.io/BradpittLai/pen/MWByagg?editors=1010)|
|Amberhh#2465|[codepen](https://codepen.io/Amberhh/pen/RwBrXBP) |
|hungya#0773|[codepen](https://codepen.io/hungya777/pen/PoBNPvr?editors=0011) |
|心幻羽#0056|[codepen](https://codepen.io/linglingsyu/pen/qByZbEy?editors=1111) |
|Wendy77#8049|[Codepen](https://codepen.io/Wendy__/pen/rNrexaG)|
|老皮博士#8050|[Codepen](https://codepen.io/li0406/pen/JjBXGwV?editors=0011)|
|ABOOS#6276|[Codepen](https://codepen.io/guhungyin/pen/ZEjWQVR?editors=0012)|
|Asher Xu#9297|[Codepen](https://codepen.io/kirakira72/pen/wvxGMRg)|
|Paul#7426|[CodePen](https://codepen.io/paul-1997/pen/jOpqqBK?editors=0011)|
|yoyo123456#0577|[CodePen](https://codepen.io/hungyoyo/pen/dyjMMJX?editors=0011)|
|小木馬#8760|[CodePen](https://codepen.io/wmmtbcsd/pen/rNreega?editors=0010)|
|hannahTW#2224|[CodePen](https://codepen.io/hangineer/pen/poZgMaW?editors=0011)|
|DIO大人#4776|[CodePen](https://codepen.io/oscar-2283/pen/GRBZjga)|
|xin#1214|[CodePen](https://codepen.io/SiaoYao/pen/zYLqKdj)|
|Yishan#4902|[CodePen](https://codepen.io/gdjrehhw-the-animator/pen/WNKwvYa?editors=0011)|
|Mia小福#4473|[CodePen](https://codepen.io/a0950271/pen/vYaGXrB)|
|enolachen#8031|[CodePen](https://codepen.io/Chen-Enola/pen/poZyExd)|
|Austyn#0949|[CodePen](https://codepen.io/fish90547/pen/vYaGyzm?editors=0012)|
|jacky010080#0880|[CodePen](https://codepen.io/Yen-Jung-Chen/pen/yLqOVqw?editors=1011)|
Zack_P#1805|[CodePen](https://codepen.io/tmzazirh-the-animator/pen/WNKwoLa?editors=1011)|
ViNci#4273|[CodePen](https://codepen.io/ViNciSyo/pen/oNMxeQR)|
| 薯餅#3581             | [CodePen](https://codepen.io/ColdingPoTaTo/pen/OJwNjBX)                     |     |                 |                                                                 |
| --------------------- | --------------------------------------------------------------------------- | --- | --------------- | --------------------------------------------------------------- |
| 柔柔#1716             | [Codepen](https://codepen.io/rouchen/pen/JjBXrjq?editors=0011)              |     |                 |                                                                 |
| Bella_#1587           | [Codepen](https://codepen.io/Chen-Bella/pen/RwBaLNr)                        |     |                 |                                                                 |
| 楊苡安_#2752          | [hackmd](https://hackmd.io/@L7K9-66lSeagS28AP0_GjQ/Hk7T-AiFo)               |     |                 |                                                                 |
| kuku#3118             | [Codepen](https://codepen.io/mengting-ku/pen/yLqOzGw)                       |     |                 |                                                                 |
| How#5806              | [Codepen](https://codepen.io/howtobefine/pen/ZEjWrWq)                       |     |                 |                                                                 |
| SASIMI#5099           | [Codepen](https://codepen.io/sashimi1327/pen/wvxGmMY)                       |     |                 |                                                                 |
| Knock59487#9114       | [Codepen](https://codepen.io/Zack88/pen/eYjZLVy?editors=1111)               |     |                 |                                                                 |
| shiuan#4721           | [Codepen](https://codepen.io/prankaChang/pen/rNreqyP?editors=0011)          |     |                 |                                                                 |
| FiReBrO #0557         | [Codepen](https://codepen.io/firebro42/pen/qByZwyL)                         |     |                 |                                                                 |
| Ron Liang#7277        | [Codepen](https://codepen.io/ron-go/pen/VwBaovG)                            |     |                 |                                                                 |
| 阿鑫#4346             | [CodePen](https://codepen.io/Neil1024/pen/eYjzNmK?editors=0011)             |     |                 |                                                                 |
| PayRoom#8328          | [CodePen](https://codepen.io/water38198/pen/ZEjOGMw)                        |     |                 |                                                                 |
| sophiee#7015          | [codepen](https://codepen.io/sophiee2727/pen/qByNaKJ?editors=1011)          |     |                 |                                                                 |
| Hironaka#7367         | [codepen](https://codepen.io/Hironaka0815/pen/rNrevvd?editors=0011)         |     |                 |                                                                 |
| yoyo#1003             | [codepen](https://codepen.io/pen/WNKxpRQ)                                   |     |                 |                                                                 |
| 你看我像是會玩嗎#1866 | [codepen](https://codepen.io/hasagg/pen/WNKxEXr)                            |     | Yuna Huang#2692 | [codepen](https://codepen.io/Yuna1002/pen/XWBKgGN?editors=0011) |
| 阿沁#8176             | [CodePen](https://codepen.io/a8322342/pen/yLqJQdN)                          |     |                 |                                                                 |
| Hazel.#6020           | [CodePen](https://codepen.io/Hazelhsieh/pen/WNKrZXa)                        |     |                 |                                                                 |
| kevin#6131            | [CodePen](https://codepen.io/xlqjezvc-the-encoder/pen/wvxWNNP?editors=0011) |     |                 |                                                                 |
| Bassjim#0118          | [CodePen](https://codepen.io/unrtxbaq/pen/rNrMBqo?editors=1111)             |     |                 |                                                                 |
| 竹輪#3335             | [CodePen](https://codepen.io/chikuwa0120/pen/jOpMOpR)                       |     |                 |                                                                 |
| 阿異#4776  |    [Codepen](https://codepen.io/yani21399/pen/VwBKWEz)                                                                         |     |                 |                                                                 |
|Wei#2330|[Codepen](https://codepen.io/ixfjxrbo-the-typescripter/pen/BaPQREp)|
|popcorn_3q#9893|[Codepen](https://codepen.io/arnyrpqt-the-sasster/pen/oNMBopg)|
|Shuo#1596|[Codepen](https://codepen.io/chiangchungshuo/pen/OJwWOoj)|
| Jenny真#7532 | [CodePen](https://codepen.io/wei-chen-wu/pen/xxJgaag?editors=0010) |
| 艸良#2846 | [CodePen](https://codepen.io/momoninainai/pen/dyjvpRN?editors=1010) |
| YI#0863 | [CodePen](https://codepen.io/YI0305/pen/YzjZZeQ?editors=0010) |
|MengLin#3001|[CodePen](https://codepen.io/aacj2642/pen/KKBWmja?editors=0012)|
|Yiru#0236|[Codepen](https://codepen.io/yiru94/pen/XWBRWGy?editors=0011)|
|Judy Wei#6103|[Codepen](https://codepen.io/Judy0718/pen/xxJdjNZ)|
|IreneY#0086|[CodePen](https://codepen.io/HalfPlannedJourney/pen/jOpmvNa)|
|   YU#0618   | [Codepen](https://codepen.io/yoken_/pen/wvxeoNZ)        |
| GOD_QWERTYUIOPLKJLKLLOINJ_MASTER#4922  | [Codepen](https://codepen.io/sho666/pen/dyjVYWJ)        |
| Cookie SSS#6991  | [Codepen](https://codepen.io/sqhjikpa-the-selector/pen/KKBXXbJ?editors=1010)        |
| 阿蘇#8531 | [Codepen](https://codepen.io/susu3131/pen/yLqpBdQ?editors=0011)        |
|Tuhacrt#0008|[codepen](https://codepen.io/Tuhacrt/pen/KKBozJq)|
|周周#3503|[Codepen](https://codepen.io/jhoujhou-the-decoder/pen/bGjKJvL?editors=0012)|
|Jujubeleven#1036|[Codepen](https://codepen.io/jujubeleven/pen/BaPGyQa?editors=0012)|
|Eason#7884|[Codepen](https://codepen.io/ASLEO/pen/xxavNZr)|

