# ==討論日期 : 5/3 ( 五 )==
||謝謝大家一起複習完JS核心篇,但沒有結束唷唷唷,下禮拜Vue會繼續複習的XD||
## 上週複習
- [討論日期:4/26](https://hackmd.io/R6CcxuE_RNimMEGdWZPSbA)
<br>
## 💖 本週複習 🥰
#### ==題目一==
```js=
var myName = '全域';
function callName() {
console.log(this);
console.log(this.myName);
}
callName();
```
答:
window
全域
<br>
#### ==題目二==
請寫出執行結果
```js=
var abc1='123';
function show(){
var abc2='456';
alert(abc1+' & '+abc2);
}
show();
alert(abc1+'&'+abc2);
```
答:
123 & 456
報錯:abc2 is not defined
<br>
#### ==題目三==
請寫出執行結果
```js=
var b = 1;
function print() {
var b = a = 2;
console.log(a,b);
}
print();
console.log(a,b);
```
答:
2,2
2,1
<br>
#### ==題目四==
如何把上題輸出改成
```js=
< 2 2
< 1 1
```
答:
```js=
var a = 1;
var b = 1;
function print() {
var a = 2;
var b = 2;
console.log(a,b);
}
print();
console.log(a,b);
```
<br>
#### ==題目五==
請寫出執行結果
```js=
var a = [1];
var b = a;
a[0] = 2;
console.log(b);
```
答:`[2]`
<br>
#### ==題目六==
請問 foo 跟 bar 的值是?
```js=
var foo = {n: 1};
var bar = foo;
foo.x = foo = {n: 2};
```
答:
foo:`{n:2}`
bar:`{
n: 1,
x: {n: 2}
}`
<br>
#### ==題目八==
請問結果如何?
```js=
function b() {
console.log(a);
function a() {};
var a = 3;
}
b();
```
答:`function a() {}`
<br>
#### ==題目九==
請問結果如何?
```js=
var a = {
a: 10
};
var b = a.a = a.a * a.a;
console.log(b)
```
答:`100`
<br>
#### ==題目十==
請問結果如何?
```js=
var newList = [1, 2, 3].push(4);
console.log(newList.push(5));
```
選擇:
1. [1, 2, 3, 4, 5]
2. Error
答:2
<br>
#### ==題目十一==
請問結果如何?
```js=
function a() {
this.a.a = 1;
}
a.a = 2;
a();
console.log(a.a);
```
答:`1`
<br>
#### ==題目十二==
請問結果如何?
```js=
console.log(typeof typeof 1)
```
答:`string`
<br>
#### ==題目十三==
請問結果如何?
```js=
var a = [1, 2, 3];
a[19] = 20;
console.log(a.length);
```
答:`20 (中間都是 undefined)`
<br>
#### ==題目十三==
請問結果如何?
```js=
console.log(typeof 'a' + 'a')
```
答:`stringa`
<br>
#### ==題目十四==
請問結果如何?
```js=
var a = 10;
console.log(a++ * a++);
```
答:`110`
GPT 回答:
在這個程式碼中,a 最初被賦值為 10。然後,console.log(a++ * a++) 被執行。
a++ 是一個後置遞增運算子。這意味著,a 的值會在運算之後增加 1。所以在第一個 a++ 被使用時,它會被當作 10 並且 a 的值會變成 11。接著,第二個 a++ 也是一樣,它會被當作 11 並且 a 的值會變成 12。
因此,console.log(a++ * a++) 實際上相當於 console.log(10 * 11)。而 10 * 11 等於 110。
<br>
#### ==題目十五==
請問結果如何?
```js=
console.log(10 == 10n);
console.log(10 === 10n);
```
答:
true
false
<br>
#### ==題目十六==
請問結果如何?
```js=
console.log(1 < 2 < 3)
console.log(3 > 2 > 1)
```
答:
true
false
1 < 2 回傳 true,轉型 1 < 3,回傳 true
3 > 2 回傳 true,轉型 1 > 1,回傳 false
<br>
#### ==題目十七==
請問結果如何?
```js=
var a = 1;
function fn() {
a = fn.a;
}
fn.a = 2;
console.log(a);
```
答:`1`
<br>
#### ==題目十八==
請問結果如何?
```js=
var a = {};
a.a = a;
console.log(a.a.a === a.a);
```
答:`true`
<br>
#### ==題目十九==
請問結果如何?
```js=
var name = '全域'
var obj = {
name: '區域',
callName: function () {
console.log(this.name);
}
};
(function () {
var a = obj.callName;
a();
})()
```
選擇:
1. 全域
2. 區域
3. 領域展開 (麻煩左轉動漫區)
答:`1`
提示:傳統函式看調用方式。
<br>
#### ==題目二十==
請問執行順序如何?
```js=
<script>
console.log('script start');
setTimeout(function () {
console.log('setTimeout 1 callback');
}, 1000);
new Promise(function (resolve, reject) {
console.log('promise 1 resolve');
resolve();
}).then(function () {
console.log('promise 1 callback');
});
new Promise(function (resolve, reject) {
console.log('promise 2 resolve');
resolve();
}).then(function () {
console.log('promise 2 callback');
});
setTimeout(function () {
console.log('setTimeout 2 callback');
}, 1000);
console.log('script end');
</script>
```
答:
```
script start
promise 1 resolve
promise 2 resolve
script end
promise 1 callback
promise 2 callback
setTimeout 1 callback
setTimeout 2 callback
```
<br>
#### ==題目二一==
請問執行結果如何?
```js=
var name = '小明';
function easyCard(base = 500) {
var money = base;
return function(update = 10) {
money = money + update;
return money;
}
}
var MingEasyCard = easyCard(100);
MingEasyCard();
MingEasyCard();
console.log(MingEasyCard());
```
<br>
#### ==題目二二==
請問執行順序如何?
```js=
var family = {
myName: '小明家',
}
function fn(para1, para2) {
console.log(this, para1, para2);
}
var fn2 = fn.bind(family);
fn2();
```
<br>
#### ==題目二三==
請問執行順序如何?
```js=
```
<br>