本篇文章主要介紹 javascript 程式語言的基本語法
- 變數
- 陣列
- 運算符號
- if condition
- for loop
- for each
- function
- 常數物件
變數
1 2 3 4 5 6
| const a = 0 const b = 0.01 const c = "message" const d = true const e = null const f = undefined
|
陣列
1 2
| const a = [] const a = [1, 2, 3]
|
運算符號
1 2 3 4 5 6 7 8 9
| a === b a !== b a > b a >= b a < b a <= b !a a && b a || b
|
if condition
1 2 3 4 5 6 7
| if (a > b) { ... } else if (a < b) { ... } else { ... }
|
for loop
1 2 3
| for (let i = 0; i < 10; i++) { ... }
|
for each
1 2 3
| for (const element of array){ ... }
|
function
1 2 3 4 5 6 7 8 9 10 11 12
| function Calculate() { ... }
function Calculate(a) { ... }
function Calculate(a) { ... return 0 }
|
常數物件
宣告
1 2
| const valueByKey = {} const valueByKey = { "Id": 0 }
|
檢查存在
1 2 3
| const valueByKey = { "Id": 0 } const key = "Id" const isExisted = key in valueByKey
|
賦值
1 2 3 4
| const valueByKey = {} const key = "Id" const value = 0 valueByKey[key] = value
|
取值
1 2 3
| const valueByKey = { "Id": 0 } const key = "Id" const value = valueByKey[key]
|