1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
|
---
title: 陳述式與宣告
slug: Web/JavaScript/Reference/Statements
tags:
- JavaScript
- Reference
- statements
translation_of: Web/JavaScript/Reference/Statements
---
<div>{{jsSidebar("Statements")}}</div>
<p>JavaScript 應用程式由適當的陳述式組成。一個單一的陳述式可以跨用好幾行。 多個陳述式也可以藉由分號分隔來寫在同一行。 這不是一個關鍵字,而是一群關鍵字。</p>
<h2 id="陳述式與宣告分類">陳述式與宣告分類</h2>
<p>For an alphabetical listing see the sidebar on the left.</p>
<h3 id="流程控制">流程控制</h3>
<dl>
<dt>{{jsxref("Statements/block", "Block")}}</dt>
<dd>A block statement is used to group zero or more statements. The block is delimited by a pair of curly brackets.</dd>
<dt>{{jsxref("Statements/break", "break")}}</dt>
<dd>中斷當下的迴圈、條件判斷(switch)或是標籤(label)陳述式,並將程式流程轉到被中斷陳述式後的陳述式。</dd>
<dt>{{jsxref("Statements/continue", "continue")}}</dt>
<dd>Terminates execution of the statements in the current iteration of the current or labeled loop, and continues execution of the loop with the next iteration.</dd>
<dt>{{jsxref("Statements/Empty", "Empty")}}</dt>
<dd>An empty statement is used to provide no statement, although the JavaScript syntax would expect one.</dd>
<dt>{{jsxref("Statements/if...else", "if...else")}}</dt>
<dd>當特定的條件為真時執行一段陳述式,若為假則另一段陳述式就會被執行。</dd>
<dt>{{jsxref("Statements/switch", "switch")}}</dt>
<dd>Evaluates an expression, matching the expression's value to a case clause, and executes statements associated with that case.</dd>
<dt>{{jsxref("Statements/throw", "throw")}}</dt>
<dd>Throws a user-defined exception.</dd>
<dt>{{jsxref("Statements/try...catch", "try...catch")}}</dt>
<dd>Marks a block of statements to try, and specifies a response, should an exception be thrown.</dd>
</dl>
<h3 id="宣告">宣告</h3>
<dl>
<dt>{{jsxref("Statements/var", "var")}}</dt>
<dd>Declares a variable, optionally initializing it to a value.</dd>
<dt>{{jsxref("Statements/let", "let")}}</dt>
<dd>Declares a block scope local variable, optionally initializing it to a value.</dd>
<dt>{{jsxref("Statements/const", "const")}}</dt>
<dd>Declares a read-only named constant.</dd>
</dl>
<h3 id="函數與類別(Class)">函數與類別(Class)</h3>
<dl>
<dt>{{jsxref("Statements/function", "function")}}</dt>
<dd>用指定的變數宣告一個函數</dd>
<dt>{{jsxref("Statements/function*", "function*")}}</dt>
<dd>Generators functions enable writing <a href="/en-US/docs/Web/JavaScript/Guide/The_Iterator_protocol">iterators</a> more easily.</dd>
<dt>{{jsxref("Statements/async_function", "async function")}}</dt>
<dd>Declares an async function with the specified parameters.</dd>
<dt>{{jsxref("Statements/return", "return")}}</dt>
<dd>Specifies the value to be returned by a function.</dd>
<dt>{{jsxref("Statements/class", "class")}}</dt>
<dd>Declares a class.</dd>
</dl>
<h3 id="迭代(Iteration)">迭代(Iteration)</h3>
<dl>
<dt>{{jsxref("Statements/do...while", "do...while")}}</dt>
<dd>Creates a loop that executes a specified statement until the test condition evaluates to false. The condition is evaluated after executing the statement, resulting in the specified statement executing at least once.</dd>
<dt>{{jsxref("Statements/for", "for")}}</dt>
<dd>Creates a loop that consists of three optional expressions, enclosed in parentheses and separated by semicolons, followed by a statement executed in the loop.</dd>
<dt>{{deprecated_inline}} {{non-standard_inline()}} {{jsxref("Statements/for_each...in", "for each...in")}}</dt>
<dd>Iterates a specified variable over all values of object's properties. For each distinct property, a specified statement is executed.</dd>
<dt>{{jsxref("Statements/for...in", "for...in")}}</dt>
<dd>Iterates over the enumerable properties of an object, in arbitrary order. For each distinct property, statements can be executed.</dd>
<dt>{{jsxref("Statements/for...of", "for...of")}}</dt>
<dd>Iterates over iterable objects (including {{jsxref("Global_Objects/Array","arrays","","true")}}, array-like objects, <a href="/en-US/docs/JavaScript/Guide/Iterators_and_Generators">iterators and generators</a>), invoking a custom iteration hook with statements to be executed for the value of each distinct property.</dd>
<dt>{{jsxref("Statements/while", "while")}}</dt>
<dd>Creates a loop that executes a specified statement as long as the test condition evaluates to true. The condition is evaluated before executing the statement.</dd>
</dl>
<h3 id="其他">其他</h3>
<dl>
<dt>{{jsxref("Statements/debugger", "debugger")}}</dt>
<dd>Invokes any available debugging functionality. If no debugging functionality is available, this statement has no effect.</dd>
<dt>{{jsxref("Statements/export", "export")}}</dt>
<dd>Used to export functions to make them available for imports in external modules, another scripts.</dd>
<dt>{{jsxref("Statements/import", "import")}}</dt>
<dd>Used to import functions exported from an external module, another script.</dd>
<dt>{{jsxref("Statements/label", "label")}}</dt>
<dd>Provides a statement with an identifier that you can refer to using a <code>break</code> or <code>continue</code> statement.</dd>
</dl>
<dl>
<dt>{{deprecated_inline}} {{jsxref("Statements/with", "with")}}</dt>
<dd>Extends the scope chain for a statement.</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-12', 'Statements')}}</td>
<td>{{Spec2('ES1')}}</td>
<td>Initial definition</td>
</tr>
<tr>
<td>{{SpecName('ES3', '#sec-12', 'Statements')}}</td>
<td>{{Spec2('ES3')}}</td>
<td></td>
</tr>
<tr>
<td>{{SpecName('ES5.1', '#sec-12', 'Statements')}}</td>
<td>{{Spec2('ES5.1')}}</td>
<td></td>
</tr>
<tr>
<td>{{SpecName('ES6', '#sec-ecmascript-language-statements-and-declarations', 'ECMAScript Language: Statements and Declarations')}}</td>
<td>{{Spec2('ES6')}}</td>
<td>New: function*, let, for...of, yield, class</td>
</tr>
<tr>
<td>{{SpecName('ESDraft', '#sec-ecmascript-language-statements-and-declarations', 'ECMAScript Language: Statements and Declarations')}}</td>
<td>{{Spec2('ESDraft')}}</td>
<td></td>
</tr>
</tbody>
</table>
<h2 id="瀏覽器相容性">瀏覽器相容性</h2>
<p>{{Compat("javascript.statements")}}</p>
<h2 id="參見">參見</h2>
<ul>
<li><a href="/docs/Web/JavaScript/Reference/Operators">運算式與運算子</a></li>
</ul>
|