pFad - Phone/Frame/Anonymizer/Declutterfier! Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

URL: http://developer.mozilla.org/zh-TW/docs/Web/JavaScript/Reference/Operators

此頁面由社群從英文翻譯而來。了解更多並加入 MDN Web Docs 社群。

View in English Always switch to English

運算式與運算子

本章節記錄了所有 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 and object["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.

遞增與遞減

字尾/字首遞增與字尾/字首遞減運算子。

A++

字尾遞增運算子。

A--

字尾遞減運算子。

++A

字首遞增運算子。

--A

字首遞減運算子。

一元運算子

一元運算是指只需要使用一個運算元的運算。

delete

delete 運算子可刪除物件中的屬性。

void

void 運算子可放棄一個運算式的回傳值。

typeof

typeof 運算子可以判斷一個指定物件的型態。

+

一元正運算子可以轉換其運算元成為數值 (Number) 型態。

-

一元負運算子可以轉換其運算元成為數值 (Number) 型態並轉為負值。

~

元位 NOT 運算子。

!

邏輯 NOT 運算子。

算術運算子

算術運算子會要用到數值 (不論是字面值或者變數) 做為運算元,並且會回傳單一數值結果。

+

加法運算子。

-

減法運算子。

/

除法運算子。

*

乘法運算子。

%

餘數運算子。

**

指數運算子。

關係運算子

比較運算子會比較其運算元並根據比較的結果是否成立回傳一個 Boolean 值的結果。

in

in 運算子會判斷一個物件是否有指定的屬性。

instanceof

instanceof 運算子會判斷一個物件是否為另一個物件的實例。

<

小於運算子。

>

大於運算子。

<=

小於等於運算子。

>=

大於等於運算子。

備註:=> is not an operator, but the notation for Arrow functions.

相等運算子

執行相對運算子後的結果為比較結果是否成立的 Boolean 值。

==

相等運算子。

!=

不相等運算子。

===

恆等運算子。

!==

不恆等運算子。

位元移位運算子

用來位移運算元所有位元的運算。

<<

左移位元運算子。

>>

右移位元運算子。

>>>

右移無號位元運算子。

二元位元運算子

位元運算子將其運算元當做是 32 位元 (32 個零與一) 的數值處理並回傳標準 JavaScript 數值。

&

位元 AND。

|

位元 OR。

^

位元 XOR。

二元邏輯運算子

邏輯運算子一般用在處理布林 (邏輯) 值,它們存在的地方會回傳一個布林 (Boolean) 值。

&&

邏輯 AND。

||

邏輯 OR。

條件 (三元) 運算子

(condition ? ifTrue : ifFalse)

條件運算子會根據條件的邏輯值判斷並回傳其中一個值。

賦值運算子

賦值運算子會根據其右側運算元的數值處理後賦值給其左側的運算元。

=

賦值運算子。

*=

乘法賦值。

/=

除法賦值。

%=

餘數賦值。

+=

加法賦值。

-=

減法賦值。

<<=

左移賦值。

>>=

右移賦值。

>>>=

無號右移賦值。

&=

位元 AND 賦值。

^=

位元 XOR 賦值。

|=

位元 OR 賦值。

{a, b} = {a:1, b:2} [a, b] = [1, 2]

解構讓你可使用如陣列或物件書寫格式來賦值給陣列或物件的屬性。

逗號運算子

,

逗號運算子允許在一個敘述句中執行多個運算式並回傳最後一個運算式的結果。

非標準功能

Non-standard 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 one yield expression.

Non-standard Expression closures

The expression closure syntax is a shorthand for writing simple function.

Non-standard [for (x of y) x]

Array comprehensions.

Non-standard (for (x of y) y)

Generator comprehensions.

技術規格

Specification
ECMAScript® 2027 Language Specification
# prod-CoalesceExpression
ECMAScript® 2027 Language Specification
# sec-assignment-operators
ECMAScript® 2027 Language Specification
# sec-unsigned-right-shift-operator
ECMAScript® 2027 Language Specification
# sec-relational-operators
ECMAScript® 2027 Language Specification
# sec-generator-function-definitions
ECMAScript® 2027 Language Specification
# sec-multiplicative-operators
ECMAScript® 2027 Language Specification
# sec-import-calls
ECMAScript® 2027 Language Specification
# sec-object-initializer
ECMAScript® 2027 Language Specification
# sec-async-function-definitions
ECMAScript® 2027 Language Specification
# sec-equality-operators
ECMAScript® 2027 Language Specification
# prod-YieldExpression
ECMAScript® 2027 Language Specification
# sec-comma-operator
ECMAScript® 2027 Language Specification
# sec-bitwise-not-operator
ECMAScript® 2027 Language Specification
# prod-LogicalANDExpression
ECMAScript® 2027 Language Specification
# sec-void-operator
ECMAScript® 2027 Language Specification
# prod-BitwiseORExpression
ECMAScript® 2027 Language Specification
# sec-postfix-increment-operator
ECMAScript® 2027 Language Specification
# prod-BitwiseANDExpression
ECMAScript® 2027 Language Specification
# sec-this-keyword
ECMAScript® 2027 Language Specification
# sec-addition-operator-plus
ECMAScript® 2027 Language Specification
# sec-grouping-operator
ECMAScript® 2027 Language Specification
# prod-OptionalExpression
ECMAScript® 2027 Language Specification
# sec-subtraction-operator-minus
ECMAScript® 2027 Language Specification
# sec-async-generator-function-definitions
ECMAScript® 2027 Language Specification
# sec-delete-operator
ECMAScript® 2027 Language Specification
# sec-logical-not-operator
ECMAScript® 2027 Language Specification
# sec-destructuring-assignment
ECMAScript® 2027 Language Specification
# sec-destructuring-binding-patterns
ECMAScript® 2027 Language Specification
# sec-null-value
ECMAScript® 2027 Language Specification
# sec-left-shift-operator
ECMAScript® 2027 Language Specification
# sec-new-operator
ECMAScript® 2027 Language Specification
# sec-typeof-operator
ECMAScript® 2027 Language Specification
# sec-generator-function-definitions-runtime-semantics-evaluation
ECMAScript® 2027 Language Specification
# sec-unary-plus-operator
ECMAScript® 2027 Language Specification
# sec-exp-operator
ECMAScript® 2027 Language Specification
# prod-BitwiseXORExpression
ECMAScript® 2027 Language Specification
# sec-signed-right-shift-operator
ECMAScript® 2027 Language Specification
# sec-class-definitions
ECMAScript® 2027 Language Specification
# prod-ArgumentList
ECMAScript® 2027 Language Specification
# prod-PropertyDefinition
ECMAScript® 2027 Language Specification
# sec-unary-minus-operator
ECMAScript® 2027 Language Specification
# prod-SpreadElement
ECMAScript® 2027 Language Specification
# sec-postfix-decrement-operator
ECMAScript® 2027 Language Specification
# sec-property-accessors
ECMAScript® 2027 Language Specification
# prod-LogicalORExpression
ECMAScript® 2027 Language Specification
# prod-ImportMeta
ECMAScript® 2027 Language Specification
# sec-conditional-operator
ECMAScript® 2027 Language Specification
# sec-function-definitions
ECMAScript® 2027 Language Specification
# sec-built-in-function-objects
ECMAScript® 2027 Language Specification
# sec-super-keyword
HTML
# import-meta-resolve

相關文獻

pFad - Phonifier reborn

Pfad - The Proxy pFad © 2024 Your Company Name. All rights reserved.





Check this box to remove all script contents from the fetched content.



Check this box to remove all images from the fetched content.


Check this box to remove all CSS styles from the fetched content.


Check this box to keep images inefficiently compressed and original size.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy