運算式與運算子
本章節記錄了所有 JavaScript 運算式、運算子以及關鍵字。
運算式與運算子分類
以字母排列的清單請參考左側的側邊欄。
主要運算式
在 JavaScript 中基本的關鍵字與一般的運算式。
this
-
this
關鍵字可以參考執行函數的所在位置。 function
-
function
關鍵字可以定義一個函數運算式。 class
-
class
關鍵字可以定義一個類別運算式。 function*
-
function*
關鍵字可以定義一個 Generator 函數運算式 yield
-
暫停與繼續一個產生器 (Generator) 函數。
yield*
-
轉交另一個產生器 (Generator) 函數或可迭代 (Iterable) 的物件。
-
實驗性質
async function*
-
async
函數可以定義一個非同步函數運算式。 -
實驗性質
await
-
暫停與繼續一個非同步函數並等候承諾的結果/拒絕。
[]
-
陣列初始化/書寫格式。
{}
-
物件初始化/書寫格式。
/ab+c/i
-
正規表示法書寫格式。
( )
-
分組運算子。
左手邊運算式
左側值為賦值的目標。
- Property accessors
-
成員運算子可存取物件的屬性或方法 (
object.property
andobject["property"]
)。 new
-
new
運算子可以建立一個建構子 (Constructor) 的實例。 - new.target
-
在建構子中
new.target
可以參考被new
呼叫的建構子 (Constructor) 。 super
-
super
關鍵字可以呼叫父建構子 (Constructor) 。 ...obj
-
The spread operator allows an expression to be expanded in places where multiple arguments (for function calls) or multiple elements (for array literals) are expected.
遞增與遞減
一元運算子
算術運算子
關係運算子
比較運算子會比較其運算���並根據比較的結果是否成立回傳一個 Boolean
值的結果。
in
-
in
運算子會判斷一個物件是否有指定的屬性。 instanceof
-
instanceof
運算子會判斷一個物件是否為另一個物件的實例。 <
-
小於運算子。
>
-
大於運算子。
<=
-
小於等於運算子。
>=
-
大於等於運算子。
備註: => is not an operator, but the notation for Arrow functions.
相等運算子
位元移位運算子
二元位元運算子
二元邏輯運算子
條件 (三元) 運算子
(condition ? ifTrue : ifFalse)
-
條件運算子會根據條件的邏輯值判斷並回傳其中一個值。
賦值運算子
逗號運算子
,
-
逗號運算子允許在一個敘述句中執行多個運算式並回傳最後一個運算式的結果。
非標準功能
- 非標準 Legacy generator function
-
The
function
keyword can be used to define a legacy generator function inside an expression. To make the function a legacy generator, the function body should contains at least oneyield
expression. - 非標準 Expression closures
-
The expression closure syntax is a shorthand for writing simple function.
-
非標準
[for (x of y) x]
-
Array comprehensions.
-
非標準
(for (x of y) y)
-
Generator comprehensions.