diff options
author | Peter Bengtsson <mail@peterbe.com> | 2020-12-08 14:43:23 -0500 |
---|---|---|
committer | Peter Bengtsson <mail@peterbe.com> | 2020-12-08 14:43:23 -0500 |
commit | 218934fa2ed1c702a6d3923d2aa2cc6b43c48684 (patch) | |
tree | a9ef8ac1e1b8fe4207b6d64d3841bfb8990b6fd0 /files/zh-tw/web/javascript/reference/operators/index.html | |
parent | 074785cea106179cb3305637055ab0a009ca74f2 (diff) | |
download | translated-content-218934fa2ed1c702a6d3923d2aa2cc6b43c48684.tar.gz translated-content-218934fa2ed1c702a6d3923d2aa2cc6b43c48684.tar.bz2 translated-content-218934fa2ed1c702a6d3923d2aa2cc6b43c48684.zip |
initial commit
Diffstat (limited to 'files/zh-tw/web/javascript/reference/operators/index.html')
-rw-r--r-- | files/zh-tw/web/javascript/reference/operators/index.html | 301 |
1 files changed, 301 insertions, 0 deletions
diff --git a/files/zh-tw/web/javascript/reference/operators/index.html b/files/zh-tw/web/javascript/reference/operators/index.html new file mode 100644 index 0000000000..e6efa9a181 --- /dev/null +++ b/files/zh-tw/web/javascript/reference/operators/index.html @@ -0,0 +1,301 @@ +--- +title: 運算式與運算子 +slug: Web/JavaScript/Reference/Operators +tags: + - NeedsTranslation + - TopicStub + - 運算子 +translation_of: Web/JavaScript/Reference/Operators +--- +<div>{{jsSidebar("Operators")}}</div> + +<p>本章節記錄了所有 JavaScript 運算式、運算子以及關鍵字。</p> + +<h2 id="運算式與運算子分類">運算式與運算子分類</h2> + +<p>以字母排列的清單請參考左側的側邊欄。</p> + +<h3 id="主要運算式">主要運算式</h3> + +<p>在 JavaScript 中基本的關鍵字與一般的運算式。</p> + +<dl> + <dt>{{jsxref("Operators/this", "this")}}</dt> + <dd><code>this</code> 關鍵字可以參考執行函數的所在位置。</dd> + <dt>{{jsxref("Operators/function", "function")}}</dt> + <dd><code>function</code> 關鍵字可以定義一個函數運算式。</dd> + <dt>{{jsxref("Operators/class", "class")}}</dt> + <dd><code>class</code> 關鍵字可以定義一個類別運算式。</dd> + <dt>{{jsxref("Operators/function*", "function*")}}</dt> + <dd><code>function*</code> 關鍵字可以定義一個 Generator 函數運算式</dd> + <dt>{{jsxref("Operators/yield", "yield")}}</dt> + <dd>暫停與繼續一個產生器 (Generator) 函數。</dd> + <dt>{{jsxref("Operators/yield*", "yield*")}}</dt> + <dd>轉交另一個產生器 (Generator) 函數或可迭代 (Iterable) 的物件。</dd> + <dt>{{experimental_inline}} {{jsxref("Operators/async_function", "async function*")}}</dt> + <dd><code>async</code> 函數可以定義一個非同步函數運算式。</dd> + <dt>{{experimental_inline}} {{jsxref("Operators/await", "await")}}</dt> + <dd>暫停與繼續一個非同步函數並等候承諾的結果/拒絕。</dd> + <dt>{{jsxref("Global_Objects/Array", "[]")}}</dt> + <dd>陣列初始化/書寫格式。</dd> + <dt>{{jsxref("Operators/Object_initializer", "{}")}}</dt> + <dd>物件初始化/書寫格式。</dd> + <dt>{{jsxref("Global_Objects/RegExp", "/ab+c/i")}}</dt> + <dd>正規表示法書寫格式。</dd> + <dt>{{jsxref("Operators/Grouping", "( )")}}</dt> + <dd>分組運算子。</dd> +</dl> + +<h3 id="左手邊運算式">左手邊運算式</h3> + +<p>左側值為賦值的目標。</p> + +<dl> + <dt>{{jsxref("Operators/Property_accessors", "Property accessors", "", 1)}}</dt> + <dd>成員運算子可存取物件的屬性或方法<br> + (<code>object.property</code> and <code>object["property"]</code>)。</dd> + <dt>{{jsxref("Operators/new", "new")}}</dt> + <dd><code>new</code> 運算子可以建立一個建構子 (Constructor) 的實例。</dd> + <dt><a href="/zh-TW/docs/Web/JavaScript/Reference/Operators/new.target">new.target</a></dt> + <dd>在建構子中 <code>new.target</code> 可以參考被 {{jsxref("Operators/new", "new")}} 呼叫的建構子 (Constructor) 。</dd> + <dt>{{jsxref("Operators/super", "super")}}</dt> + <dd><code>super</code> 關鍵字可以呼叫父建構子 (Constructor) 。</dd> + <dt>{{jsxref("Operators/Spread_operator", "...obj")}}</dt> + <dd>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.</dd> +</dl> + +<h3 id="遞增與遞減">遞增與遞減</h3> + +<p>字尾/字首遞增與字尾/字首遞減運算子。</p> + +<dl> + <dt>{{jsxref("Operators/Arithmetic_Operators", "A++", "#Increment")}}</dt> + <dd>字尾遞增運算子。</dd> + <dt>{{jsxref("Operators/Arithmetic_Operators", "A--", "#Decrement")}}</dt> + <dd>字尾遞減運算子。</dd> + <dt>{{jsxref("Operators/Arithmetic_Operators", "++A", "#Increment")}}</dt> + <dd>字首遞增運算子。</dd> + <dt>{{jsxref("Operators/Arithmetic_Operators", "--A", "#Decrement")}}</dt> + <dd>字首遞減運算子。</dd> +</dl> + +<h3 id="一元運算子">一元運算子</h3> + +<p>一元運算是指只需要使用一個運算元的運算。</p> + +<dl> + <dt>{{jsxref("Operators/delete", "delete")}}</dt> + <dd><code>delete</code> 運算子可刪除物件中的屬性。</dd> + <dt>{{jsxref("Operators/void", "void")}}</dt> + <dd><code>void</code> 運算子可放棄一個運算式的回傳值。</dd> + <dt>{{jsxref("Operators/typeof", "typeof")}}</dt> + <dd><code>typeof</code> 運算子可以判斷一個指定物件的型態。</dd> + <dt>{{jsxref("Operators/Arithmetic_Operators", "+", "#Unary_plus")}}</dt> + <dd>一元正運算子可以轉換其運算元成為數值 (Number) 型態。</dd> + <dt>{{jsxref("Operators/Arithmetic_Operators", "-", "#Unary_negation")}}</dt> + <dd>一元負運算子可以轉換其運算元成為數值 (Number) 型態並轉為負值。</dd> + <dt>{{jsxref("Operators/Bitwise_Operators", "~", "#Bitwise_NOT")}}</dt> + <dd>元位 NOT 運算子。</dd> + <dt>{{jsxref("Operators/Logical_Operators", "!", "#Logical_NOT")}}</dt> + <dd>邏輯 NOT 運算子。</dd> +</dl> + +<h3 id="算術運算子">算術運算子</h3> + +<p>算術運算子會要用到數值 (不論是字面值或者變數) 做為運算元,並且會回傳單一數值結果。</p> + +<dl> + <dt>{{jsxref("Operators/Arithmetic_Operators", "+", "#Addition")}}</dt> + <dd>加法運算子。</dd> + <dt>{{jsxref("Operators/Arithmetic_Operators", "-", "#Subtraction")}}</dt> + <dd>減法運算子。</dd> + <dt>{{jsxref("Operators/Arithmetic_Operators", "/", "#Division")}}</dt> + <dd>除法運算子。</dd> + <dt>{{jsxref("Operators/Arithmetic_Operators", "*", "#Multiplication")}}</dt> + <dd>乘法運算子。</dd> + <dt>{{jsxref("Operators/Arithmetic_Operators", "%", "#Remainder")}}</dt> + <dd>餘數運算子。</dd> +</dl> + +<dl> + <dt>{{jsxref("Operators/Arithmetic_Operators", "**", "#Exponentiation")}}</dt> + <dd>指數運算子。</dd> +</dl> + +<h3 id="關係運算子">關係運算子</h3> + +<p>比較運算子會比較其運算元並根據比較的結果是否成立回傳一個 <code>Boolean</code> 值的結果。</p> + +<dl> + <dt>{{jsxref("Operators/in", "in")}}</dt> + <dd><code>in</code> 運算子會判斷一個物件是否有指定的屬性。</dd> + <dt>{{jsxref("Operators/instanceof", "instanceof")}}</dt> + <dd><code>instanceof</code> 運算子會判斷一個物件是否為另一個物件的實例。</dd> + <dt>{{jsxref("Operators/Comparison_Operators", "<", "#Less_than_operator")}}</dt> + <dd>小於運算子。</dd> + <dt>{{jsxref("Operators/Comparison_Operators", ">", "#Greater_than_operator")}}</dt> + <dd>大於運算子。</dd> + <dt>{{jsxref("Operators/Comparison_Operators", "<=", "#Less_than_or_equal_operator")}}</dt> + <dd>小於等於運算子。</dd> + <dt>{{jsxref("Operators/Comparison_Operators", ">=", "#Greater_than_or_equal_operator")}}</dt> + <dd>大於等於運算子。</dd> +</dl> + +<div class="note"> +<p><strong>Note: =></strong> is not an operator, but the notation for <a href="/zh-TW/docs/Web/JavaScript/Reference/Functions/Arrow_functions">Arrow functions</a>.</p> +</div> + +<h3 id="相等運算子">相等運算子</h3> + +<p>執行相對運算子後的結果為比較結果是否成立的 <code>Boolean</code> 值。</p> + +<dl> + <dt>{{jsxref("Operators/Comparison_Operators", "==", "#Equality")}}</dt> + <dd>相等運算子。</dd> + <dt>{{jsxref("Operators/Comparison_Operators", "!=", "#Inequality")}}</dt> + <dd>不相等運算子。</dd> + <dt>{{jsxref("Operators/Comparison_Operators", "===", "#Identity")}}</dt> + <dd>恆等運算子。</dd> + <dt>{{jsxref("Operators/Comparison_Operators", "!==", "#Nonidentity")}}</dt> + <dd>不恆等運算子。</dd> +</dl> + +<h3 id="位元移位運算子">位元移位運算子</h3> + +<p>用來位移運算元所有位元的運算。</p> + +<dl> + <dt>{{jsxref("Operators/Bitwise_Operators", "<<", "#Left_shift")}}</dt> + <dd>左移位元運算子。</dd> + <dt>{{jsxref("Operators/Bitwise_Operators", ">>", "#Right_shift")}}</dt> + <dd>右移位元運算子。</dd> + <dt>{{jsxref("Operators/Bitwise_Operators", ">>>", "#Unsigned_right_shift")}}</dt> + <dd>右移無號位元運算子。</dd> +</dl> + +<h3 id="二元位元運算子">二元位元運算子</h3> + +<p>位元運算子將其運算元當做是 32 位元 (32 個零與一) 的數值處理並回傳標準 JavaScript 數值。</p> + +<dl> + <dt>{{jsxref("Operators/Bitwise_Operators", "&", "#Bitwise_AND")}}</dt> + <dd>位元 AND。</dd> + <dt>{{jsxref("Operators/Bitwise_Operators", "|", "#Bitwise_OR")}}</dt> + <dd>位元 OR。</dd> + <dt>{{jsxref("Operators/Bitwise_Operators", "^", "#Bitwise_XOR")}}</dt> + <dd>位元 XOR。</dd> +</dl> + +<h3 id="二元邏輯運算子">二元邏輯運算子</h3> + +<p>邏輯運算子一般用在處理布林 (邏輯) 值,它們存在的地方會回傳一個布林 (Boolean) 值。</p> + +<dl> + <dt>{{jsxref("Operators/Logical_Operators", "&&", "#Logical_AND")}}</dt> + <dd>邏輯 AND。</dd> + <dt>{{jsxref("Operators/Logical_Operators", "||", "#Logical_OR")}}</dt> + <dd>邏輯 OR。</dd> +</dl> + +<h3 id="條件_(三元)_運算子">條件 (三元) 運算子</h3> + +<dl> + <dt>{{jsxref("Operators/Conditional_Operator", "(condition ? ifTrue : ifFalse)")}}</dt> + <dd> + <p>條件運算子會根據條件的邏輯值判斷並回傳其中一個值。</p> + </dd> +</dl> + +<h3 id="賦值運算子">賦值運算子</h3> + +<p>賦值運算子會根據其右側運算元的數值處理後賦值給其左側的運算元。</p> + +<dl> + <dt>{{jsxref("Operators/Assignment_Operators", "=", "#Assignment")}}</dt> + <dd>賦值運算子。</dd> + <dt>{{jsxref("Operators/Assignment_Operators", "*=", "#Multiplication_assignment")}}</dt> + <dd>乘法賦值。</dd> + <dt>{{jsxref("Operators/Assignment_Operators", "/=", "#Division_assignment")}}</dt> + <dd>除法賦值。</dd> + <dt>{{jsxref("Operators/Assignment_Operators", "%=", "#Remainder_assignment")}}</dt> + <dd>餘數賦值。</dd> + <dt>{{jsxref("Operators/Assignment_Operators", "+=", "#Addition_assignment")}}</dt> + <dd>加法賦值。</dd> + <dt>{{jsxref("Operators/Assignment_Operators", "-=", "#Subtraction_assignment")}}</dt> + <dd>減法賦值。</dd> + <dt>{{jsxref("Operators/Assignment_Operators", "<<=", "#Left_shift_assignment")}}</dt> + <dd>左移賦值。</dd> + <dt>{{jsxref("Operators/Assignment_Operators", ">>=", "#Right_shift_assignment")}}</dt> + <dd>右移賦值。</dd> + <dt>{{jsxref("Operators/Assignment_Operators", ">>>=", "#Unsigned_right_shift_assignment")}}</dt> + <dd>無號右移賦值。</dd> + <dt>{{jsxref("Operators/Assignment_Operators", "&=", "#Bitwise_AND_assignment")}}</dt> + <dd>位元 AND 賦值。</dd> + <dt>{{jsxref("Operators/Assignment_Operators", "^=", "#Bitwise_XOR_assignment")}}</dt> + <dd>位元 XOR 賦值。</dd> + <dt>{{jsxref("Operators/Assignment_Operators", "|=", "#Bitwise_OR_assignment")}}</dt> + <dd>位元 OR 賦值。</dd> + <dt>{{jsxref("Operators/Destructuring_assignment", "[a, b] = [1, 2]")}}<br> + {{jsxref("Operators/Destructuring_assignment", "{a, b} = {a:1, b:2}")}}</dt> + <dd> + <p>解構賦值讓您可使用如陣列或物件書寫格式來賦值給陣列或物件的屬性。</p> + </dd> +</dl> + +<h3 id="逗號運算子">逗號運算子</h3> + +<dl> + <dt>{{jsxref("Operators/Comma_Operator", ",")}}</dt> + <dd>逗號運算子允許在一個敘述句中執行多個運算式並回傳最後一個運算式的結果。</dd> +</dl> + +<h3 id="非標準功能">非標準功能</h3> + +<dl> + <dt>{{non-standard_inline}} {{jsxref("Operators/Legacy_generator_function", "Legacy generator function", "", 1)}}</dt> + <dd>The <code>function</code> 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 {{jsxref("Operators/yield", "yield")}} expression.</dd> + <dt>{{non-standard_inline}} {{jsxref("Operators/Expression_closures", "Expression closures", "", 1)}}</dt> + <dd>The expression closure syntax is a shorthand for writing simple function.</dd> + <dt>{{non-standard_inline}} {{jsxref("Operators/Array_comprehensions", "[for (x of y) x]")}}</dt> + <dd>Array comprehensions.</dd> + <dt>{{non-standard_inline}} {{jsxref("Operators/Generator_comprehensions", "(for (x of y) y)")}}</dt> + <dd>Generator comprehensions.</dd> +</dl> + +<h2 id="技術規格">技術規格</h2> + +<table class="standard-table"> + <tbody> + <tr> + <th scope="col">技術規格</th> + <th scope="col">狀態</th> + <th scope="col">備註</th> + </tr> + <tr> + <td>{{SpecName('ES1', '#sec-11', 'Expressions')}}</td> + <td>{{Spec2('ES1')}}</td> + <td>Initial definition</td> + </tr> + <tr> + <td>{{SpecName('ES5.1', '#sec-11', 'Expressions')}}</td> + <td>{{Spec2('ES5.1')}}</td> + <td> </td> + </tr> + <tr> + <td>{{SpecName('ES6', '#sec-ecmascript-language-expressions', 'ECMAScript Language: Expressions')}}</td> + <td>{{Spec2('ES6')}}</td> + <td>New: Spread operator, destructuring assignment, <code>super</code> keyword.</td> + </tr> + <tr> + <td>{{SpecName('ESDraft', '#sec-ecmascript-language-expressions', 'ECMAScript Language: Expressions')}}</td> + <td>{{Spec2('ESDraft')}}</td> + <td> </td> + </tr> + </tbody> +</table> + +<h2 id="相關文獻">相關文獻</h2> + +<ul> + <li><a href="/zh-TW/docs/Web/JavaScript/Reference/Operators/Operator_Precedence">Operator precedence</a></li> +</ul> |