---
# System prepended metadata

title: "\U0001F3C5 Day 15 - 解構賦值和其餘運算子"
tags: [Vue 直播班 - 2023 冬季班]

---

---
tags: Vue 直播班 - 2023 冬季班
---
# 🏅 Day 15 - 解構賦值和其餘運算子

題目
---
參考：https://wcc723.github.io/javascript/2017/12/25/javascript-destructuring/

(1) 依據提示將以下程式碼用解構方式達成目標
```js=
// 題目一: 請使用解構，取出 name 及 age 的變數
const person = {
  name: '小明',
  age: 16
}
console.log(name, age); // 結果為 "小明", 16

// 題目二: 請問以下 console.log 的輸出結果為何?
let [a, b, c = 4, d = 'New', e] = [1, 2, 3];
console.log(a, b, c, d, e);
```
參考：https://wcc723.github.io/javascript/2017/12/24/javascript-spread-operator/

(2)依據提示將以下程式碼用展開方式達成目標
```js=
// 題目一: 請使用展開將 arr 的內容併入 arrNew
let arr = [1, 2, 3];
let arrNew = [?, 4, 5, 6]; // [1, 2, 3, 4, 5, 6]
console.log(arrNew);

// 題目二: 請使用展開將 restInfo 的內容併入 MingInfo
let restInfo = {
  sex: '男生',
  height: 178
}
let MingInfo = {
  name: '小明',
  age: 20,
}
```
(3) 請修改以下程式碼，透過 [參數預設值](https://developer.mozilla.org/zh-TW/docs/Web/JavaScript/Reference/Functions/Default_parameters)、[其餘參數](https://developer.mozilla.org/zh-TW/docs/Web/JavaScript/Reference/Functions/rest_parameters) 的方式完成此範例。
```js=
function getMoney(/* 填入程式碼 */) {
  return money;
}
let myMoney = getMoney();

// fruits 是一個陣列
function buySomething(/* 填入程式碼 */) {
  if(fruits.length > 2) {
    myMoney -= 200;
  }else {
    myMoney -= 100;
  }
  console.log(`小明剩下 ${myMoney} 元`);
}
buySomething('lemon', 'watermelon', 'kiwi'); // 結果為 "小明剩下 300 元"
buySomething('lemon', 'watermelon'); // 結果為 "小明剩下 200 元"
```


## 回報流程

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

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

<!-- 解答：  
(1)
// 題目一
const person = {
  name: '小明',
  age: 16
}
const {name, age} = person;
console.log(name, age);

// 題目二
1, 2, 3, "New", undefined

(2)
// 題目一
let arr = [1, 2, 3];
let arrNew = [...arr, 4, 5, 6];
console.log(arrNew);

// 題目二
let restInfo = {
  sex: '男生',
  height: 178
}
let MingInfo = {
  name: '小明',
  age: 20,
  ...restInfo
}

(3)
// fruits 是一個陣列
function getMoney(money = 500) {
  return money;
}

function buySomething(...fruits) {
	let myMoney = getMoney();
	if(fruits.length > 2) {
  	myMoney -= 200;
  }else {
  	myMoney -= 100;
  }
  console.log(`小明剩下 ${myMoney} 元`);
}
buySomething('lemon', 'watermelon', 'kiwi');
buySomething('lemon', 'watermelon');
-->




回報區
---


|   Discord    |                           CodePen / 答案                           |
|:------------:|:------------------------------------------------------------------:|
| Yijing | [CodePen](https://codepen.io/Yi-Jing-71080635/pen/NWJxOyV?editors=0010) |
| bf_tsai | [CodePen](https://codepen.io/BF-Tsai/pen/QWoyZZL?editors=1011) |
| Tippy | [CodePen](https://codepen.io/Ektodor-Wang/pen/abMdRXy) |
| XinYu | [CodePen](https://codepen.io/HsuXinYu/pen/Rwdreve?editors=0002) |
| kj | [CodePen](https://codepen.io/Eero-Chiao/pen/dyrGgEK) |
| py | [CodePen](https://codepen.io/Wpypy/pen/vYPLQBQ) |
| Chia Pin | [CodePen](https://codepen.io/joker-cat/pen/oNVbQBa) |
| Ann Chou | [CodePen](https://codepen.io/annchou_illu/pen/XWGXyma) |
| JING | [CodePen](https://codepen.io/HSUANIN0327/pen/QWoyJbj) |
| Celine 510 | [CodePen](https://codepen.io/Celine-510/pen/JjzGera) |
| Emily | [CodePen](https://codepen.io/Emily2089/pen/VwReVWg) |
| Wei_Rio | [CodePen](https://codepen.io/wei_wu/pen/WNmrYJo) |
| Peng | [CodePen](https://codepen.io/pen/?editors=0011) |
| 精靈 | [CodePen](https://codepen.io/justafairy/pen/ZEPQVQj) |
| Ting |[CodePen](https://codepen.io/liara/pen/ExMPOBO) |
| Uli| [CodePen](https://codepen.io/uli1313/pen/YzgwdEW?editors=0011) |
| dora | [CodePen](https://codepen.io/dorayu/pen/xxBwzGq?editors=1111) |
|Moreene|[CodePen](https://codepen.io/Moreene/pen/ZEPQVZN)|
|保羅|[CodePen](https://codepen.io/paul-1997/pen/poYgGjm?editors=0011)|
| Tom | [CodePen](https://codepen.io/sp1daTomm/pen/dyrGaWz) |
| PayRoom |[CodePen](https://codepen.io/water38198/pen/KKEVJqO)|
| KUN. | [CodePen](https://codepen.io/barry91205/pen/abMdXLB?editors=1011) |
| Ataraxia | [CodePen](https://codepen.io/ataraxia8888/pen/poYgGrz) |
| FangFang | [CodePen](https://codepen.io/FangFang09/pen/RwdrERa) |
| celinelinnn |[CodePen](https://codepen.io/celinephoebe/pen/qBvbgoX)|
| carrie |[CodePen](https://codepen.io/echocarriet/pen/VwReqEK)|
| Helen |[CodePen](https://codepen.io/milkteamonster/pen/dyrGrvQ?editors=0010)|
| Nelly| [CodePen](https://codepen.io/Nelly-Guo/pen/gOEPEmV?editors=0011) |
| Winnie| [CodePen](https://codepen.io/codepen-io-winnie/pen/dyrGQaB?editors=0011) |
| hedy | [CodePen](https://codepen.io/pen/?editors=1111) |
| PoRay | [CodePen](https://codepen.io/raycheng/pen/yLweZYd?editors=1111) |
| ryan.chou | [CodePen](https://codepen.io/csw8524/pen/abMdxoP) |
| kawa | [CodePen](https://codepen.io/z83xji6/pen/poYgBja?editors=1012) |
| ⭐️小正 | [CodePen](https://codepen.io/colorgolden/pen/BabjvzR?editors=1111) |
| RayRay | [CodePen](https://codepen.io/CityRay/pen/dyrGEqd) |
| ann6212 | [CodePen](https://codepen.io/yqmegupa-the-styleful/pen/eYXJwzW?editors=1012) |
| yu.t_liu | [CodePen](https://codepen.io/YuT200053/pen/mdoVNBO?editors=1111) |
| Eazy | [CodePen](https://codepen.io/Eazychen/pen/ExMKYEN?editors=1111) |
| MY | [CodePen](https://codepen.io/ahmomoz/pen/gOEPNwN?editors=1111) |
| Neil | [CodePen](https://codepen.io/Neil1024/pen/abMNdWx?editors=0012) |
| elena | [CodePen](https://codepen.io/elena0127abc/pen/jOJqqGo) |
| 小夏 | [CodePen](https://codepen.io/michaelhsia/pen/zYbqqyN) |
| jia yu | [CodePen](https://codepen.io/fjqxaznl-the-reactor/pen/rNReLqJ?editors=0011) |
|Eden|[Codepen](https://codepen.io/iseden/pen/poYyEWK)|
| SHUO | [CodePen](https://codepen.io/xrzarxkl-the-reactor/pen/dyrMNrL) |
| Fabio20 | [CodePen](https://codepen.io/fabio7621/pen/JjzXrNR?editors=1011) |
| Antonio | [CodePen](https://codepen.io/gwhvusel-the-builder/pen/vYPGypp) |
| MDFK | [CodePen](https://codepen.io/maywang/pen/wvOGpao?editors=0012) |
| Charlotte Lee | [CodePen](https://codepen.io/char849/pen/jOJqYLY) |
| Iris | [CodePen](https://codepen.io/iris831206/pen/BabKYMM?editors=0012) |
| PoWei#8484 | [CodePen](https://codepen.io/harrison-wei-lai/pen/YzgqLop?editors=1012) |
| 熊大 | [CodePen](https://codepen.io/asiating/pen/MWxKzgb) |
| macihuang | [CodePen](https://codepen.io/macy1215/pen/YzgqRyv) |
| stone4584 | [CodePen](https://codepen.io/Royen0506/pen/WNmwYVo?editors=1011) |
| cest_jessie | [CodePen](https://codepen.io/itsjessiechen/pen/eYXZQwy) |
| skypassion5000 | [CodePen](https://codepen.io/skypassion5000/pen/MWxyLXg?editors=0011) |
| sponge | [CodePen](https://codepen.io/biunpujm-the-flexboxer/pen/QWoNYVP?editors=1011) |
| WEI | [CodePen](https://codepen.io/wei-z/pen/LYaNaer?editors=1011) |
| Yang | [CodePen](https://codepen.io/Yang-J/pen/jOJqRpz?editors=0010) |
| Leo | [CodePen](https://codepen.io/Aruminiya/pen/RwdaOqG) |
| nini1202desu | [CodePen](https://codepen.io/tvxq5206/pen/vYPGvgE?editors=1011) |
| MikeLin | [CodePen](https://codepen.io/MikeLin0701/pen/LYaNwwp) |
| 風羽 | [CodePen](https://codepen.io/Joy-Huang/pen/GReZPKg?editors=0011) |
| _amaaaa | [CodePen](https://codepen.io/Alicia-Chu/pen/NWJrKBe) |
| Rock | [CodePen](https://codepen.io/xiu43317/pen/vYPKOqR) |
| Ariel | [CodePen](https://codepen.io/ariel0510/pen/YzgWVyG) |
| jeremyChan | [CodePen](https://codepen.io/nudieisgood/pen/GReqObV?editors=1112) |
| 依依 | [CodePen](https://codepen.io/Rita-Yang/pen/OJqXGdW?editors=0011) |
| .zack_p | [CodePen](https://codepen.io/Designer-PH/pen/MWxedzM?editors=1111) |
| fanshu0303 | [CodePen](https://codepen.io/JuiHsuanLee0303/pen/KKEgMjM) |
| runweiting | [CodePen](https://codepen.io/weiting14/pen/MWxjobY) |
| Vivian2857 | [CodePen](https://codepen.io/vivian_lin/pen/wvOzqPG?editors=0001) |
| haru | [CodePen](https://codepen.io/haru_portfoilo/pen/MWxjEvz?editors=0012) |
| 貢波波夫 | [CodePen](https://codepen.io/mxgrfgcr-the-bashful/pen/NWJRypX) |
| hua | [CodePen](https://codepen.io/LHua/pen/mdorZPp?editors=1111) |
| pingshian | [CodePen](https://codepen.io/pingshian0131/pen/dyrOydZ?editors=0012) |
| 黃士桓 | [codePen](https://codepen.io/shr-huan-huang/pen/ZEPLbKd) |
| xuan | [codePen](https://codepen.io/xuan0915/pen/JjzbvZB?editors=0011) |
| 狸貓 | [CodePen](https://codepen.io/tanuki320/pen/jOJybRj?editors=1011) |
| 辣椒 | [Codepen](https://codepen.io/chilichen118/pen/QWodYYO) |
| 翔.Ben | [Codepen](https://codepen.io/energy95272z/pen/RwdVmoq?editors=0012) |
| santu0868 | [CodePen](https://codepen.io/HatsumiSan/pen/poYrbxp?editors=1010) |
| peggy | [CodePen]() |
|yuling| [Codepen](https://codepen.io/igzdflpu/pen/zYbERdr)|
|關關| [Codepen](https://codepen.io/ashkuan/pen/BabJdLN)|
|WA| [Codepen](https://codepen.io/ldddl/pen/XWGwgZG)|
| yuan! | [CodePen](https://codepen.io/townyuan/pen/MWRajob) |


<!-- 

| user | [CodePen]() |

-->
