JS Conception
Basic
== and ===
==
左邊是int type右邊是string type,但是因為兩個等於會把 string 轉型為int,所以實際比對是
1 = 1
所以是true。
===
如果是三個等於(===),那麼就不會有轉換型別的問題,因此
1 === "1" //false
就是false。
Global Ececution Context
執行JS 後台會執行的事情
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
Function Execution Context
JS 後台會執行的事情
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
Hoisting
What is Hoisting??
function 或 var 在creation phase會先分配給memory
所以先執行再宣告也不會報錯
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
function expression(arrow function), const, let都不支援Hoisting,
所以不能先執行再宣告
- initializer(const)
是否需要先賦予變數值
Variables
Scope
- Global Scope(let, var, const)
- Function Scope(let, var, const)
- Block Scope(let, const)
it can only be seen inside a loop or if statement
Conculsion
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
Closure(Scope chain)
function 的變數取決於function被定義的scope
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
CallStack
是一種資料結構, 遵循last in first out
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
Functions
All functions are objects
製作大量相似的obejects
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
如果有共有的function或是property, 可以使用prototype來指向同一個memory位置, 避免memory浪費
Prototype
Prototype is a simple reference to another object; this object contains common properties and methods across all instances.
string的兩種創建方式
用constructor創造的string就會繼承prototype
但是沒必要這樣做, myName = "Dennis"即可
要使用的時候內建function時候
會自動轉換myName = new String("Dennis")

Functions methods
funtion 內部的this是對應到window而不是function本身

-
bind
可以將function本身丟回去, 但是要賦予新的變數

-
call
可以將function本身丟回去, 不用賦予新的變數

也可以傳參數

-
apply
和call一樣的用法, 只是參數要用list

Prototype Inheritance

Object.creat()
用來繼承prototype

- Function和Object都是构造函数
- Object.prototype是所有对象的顶层。
- Function的构造器指向自己

JS
Arrow function
feature
- no hoisting. 一定要先宣告再使用
- no this key word. (this key word refers to window object)
for loop
map
创建一个新的数组,其中每一个元素由调用数组中的每一个元素执行提供的函数得来。
forEach
针对每一个元素执行提供的函数。
callback promise async
一般同步的狀況
一般同步的狀況2的等待時間比較短會先打印
callback的狀況
Promise的狀況
Promise用then接正確的結果, 用catch接錯誤的結果
ASYNC的狀況
Destructing

AJAX and API
AJAX = Asynchronous JavaScript And XML
Q: Why AJAX?
A: connect with API
fetch API
promise
async
fetch如果不用async or promise
下面的code會先執行,導致沒有讀到值

CORS issue(同網域下才requast API)
https://ithelp.ithome.com.tw/articles/10268821
FAQ