JavaScript 应用程序是由许多语法正确的语句组成的。单个语句可以跨多行。如果每个语句用分号隔开,那么多个语句可以在一行中出现。本页的内容并不是一个关键字,而是一组关键字。
语句和声明(按类别分类)
若需要按字母顺序排列的列表,请参阅左侧边栏。
控制流程
-
Block
- 一个块语句可以用来管理零个或多个语句。该区块是由一对大括号分隔。
-
break
- 终止当前的循环,switch 或 label 语句,使程序跳到下一个语句执行。
-
continue
- 终止执行当前或标签循环的语句,直接执行下一个迭代循环。
-
Empty
- 空语句用来表示没有语句的情况,尽管 JavaScript 语法期望有语句提供。
-
if...else
- 如果指定的条件是 true ,则执行相匹配的一个语句,若为 false,则执行另一个语句。
-
switch
- 计算表达式,将子句于表达式的值做匹配,执行与该值相关联的语句。
-
throw
- 抛出一个用户定义的异常。
-
try...catch
- 标记一个语句块,并指定一个应该抛出异常的反馈。(Marks a block of statements to try, and specifies a response, should an exception be thrown.)
声明
函数和类
-
function
- 声明一个指定参数的函数。
-
function*
- 生成器函数使 迭代器更容易使用。
-
async function
- 使用指定的参数声明一个异步函数。
-
return
- 指定函数的返回值。
-
class
- 声明一个类。
迭代器
-
do...while
- 创建一个循环来执行语句,直到该语句条件表达式的值为 false。先执行语句,再执行条件表达式,该语句至少会执行一次。
-
for
- 创建一个由3个可选的表达式组成的循环,该循环用括号包裹,分号分割,并在循环体中执行语句。
-
for each...in
- 通过指定的变量迭代对象所有属性的值。针对每个唯一的属性,会执行指定的语句块。
-
for...in
- 无序遍历对象的可枚举属性。语句针对每个唯一的属性。
-
for...of
-
遍历可迭代的对象(包括
数组
、类数组对象、 迭代器和生成器),对每个不同属性的属性,调用一个自定义的有执行语句的迭代钩子。 -
for await...of
- 在异步可迭代对象、类数组对象、 迭代器和生成器上迭代,调用自定义迭代钩子,其中包含要为每个不同属性的值执行的语句。
-
while
- 创建一个循环语句,循环会一直持续到该语句条件表达式的值为false。先执行条件表达式,然后执行语句。
其他
-
debugger
- 调用可用的调试功能。如果没有调试功能可用,该语句不生效。
-
export
- 用来导出函数,以便这些函数能够被导入到外部模块或其他脚本中。
-
import
- 用来引入外部的模块或另一个script中导出的函数。
-
import.meta
- 向 JavaScript 模块公开上下文特定的元数据的元属性。
-
label
-
带标识的语句,与
break
或continue
语句一起使用。
-
with
- 拓展一个语句的作用域。
规范
规范 | 状态 | 备注 |
---|---|---|
ECMAScript 1st Edition (ECMA-262) Statements |
Standard | Initial definition |
ECMAScript 3rd Edition (ECMA-262) Statements |
Standard | |
ECMAScript 5.1 (ECMA-262) Statements |
Standard | |
ECMAScript 2015 (6th Edition, ECMA-262) ECMAScript Language: Statements and Declarations |
Standard | New: function*, let, for...of, yield, class |
ECMAScript Latest Draft (ECMA-262) ECMAScript Language: Statements and Declarations |
Draft |
浏览器兼容性
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out
https://github.com/mdn/browser-compat-data and send us a pull request.
Update compatibility data on GitHub
Desktop | Mobile | Server | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Legacy generator function | Chrome No support No | Edge No support No | Firefox No support 2 — 58 | IE No support No | Opera No support No | Safari No support No | WebView Android No support No | Chrome Android No support No | Firefox Android No support 4 — 58 | Opera Android No support No | Safari iOS No support No | Samsung Internet Android No support No | nodejs No support No |
async function |
Chrome Full support 55 | Edge Full support 15 | Firefox Full support 52 | IE No support No | Opera Full support 42 | Safari Full support 10.1 | WebView Android Full support Yes | Chrome Android Full support 55 | Firefox Android Full support 52 | Opera Android Full support 42 | Safari iOS Full support 10.3 | Samsung Internet Android Full support 6.0 | nodejs Full support 7.6.0
|
block |
Chrome Full support 1 | Edge Full support 12 | Firefox Full support 1 | IE Full support 11 | Opera Full support Yes | Safari Full support Yes | WebView Android Full support 1 | Chrome Android Full support 18 | Firefox Android Full support 4 | Opera Android Full support Yes | Safari iOS Full support Yes | Samsung Internet Android Full support 1.0 | nodejs Full support Yes |
break |
Chrome Full support 1 | Edge Full support 12 | Firefox Full support 1 | IE Full support 3 | Opera Full support Yes | Safari Full support Yes | WebView Android Full support 1 | Chrome Android Full support 18 | Firefox Android Full support 4 | Opera Android Full support Yes | Safari iOS Full support Yes | Samsung Internet Android Full support 1.0 | nodejs Full support Yes |
class |
Chrome Full support 49
|
Edge Full support 13 | Firefox Full support 45 | IE No support No | Opera Full support 36 | Safari Full support 10.1 | WebView Android Full support 49
|
Chrome Android Full support 49
|
Firefox Android Full support 45 | Opera Android ? | Safari iOS Full support 10.3 | Samsung Internet Android Full support 4.0
|
nodejs Full support 6.0.0 |
const |
Chrome Full support 21 | Edge Full support 12 | Firefox Full support 36
|
IE Full support 11 | Opera Full support Yes | Safari Full support 5.1 | WebView Android Full support Yes | Chrome Android Full support 25 | Firefox Android Full support 36
|
Opera Android Full support Yes | Safari iOS Full support Yes | Samsung Internet Android Full support Yes | nodejs Full support Yes |
continue |
Chrome Full support 1 | Edge Full support 12 | Firefox Full support 1 | IE Full support 3 | Opera Full support Yes | Safari Full support Yes | WebView Android Full support 1 | Chrome Android Full support 18 | Firefox Android Full support 4 | Opera Android Full support Yes | Safari iOS Full support Yes | Samsung Internet Android Full support 1.0 | nodejs Full support Yes |
debugger |
Chrome Full support 5 | Edge Full support 12 | Firefox Full support 1 | IE Full support 4 | Opera Full support Yes | Safari Full support Yes | WebView Android Full support 1 | Chrome Android Full support 18 | Firefox Android Full support 4 | Opera Android Full support Yes | Safari iOS Full support Yes | Samsung Internet Android Full support 1.0 | nodejs Full support Yes |
do...while |
Chrome Full support 1 | Edge Full support 12 | Firefox Full support 1 | IE Full support 4 | Opera Full support Yes | Safari Full support Yes | WebView Android Full support 1 | Chrome Android Full support 18 | Firefox Android Full support 4 | Opera Android Full support Yes | Safari iOS Full support Yes | Samsung Internet Android Full support 1.0 | nodejs Full support Yes |
Empty statement (; ) |
Chrome Full support 3 | Edge Full support 12 | Firefox Full support 1 | IE Full support 3 | Opera Full support Yes | Safari Full support Yes | WebView Android Full support 1 | Chrome Android Full support 18 | Firefox Android Full support 4 | Opera Android Full support Yes | Safari iOS Full support Yes | Samsung Internet Android Full support 1.0 | nodejs Full support Yes |
export |
Chrome Full support 61 | Edge Full support 16
|
Firefox Full support 60
|
IE No support No | Opera Full support 47 | Safari Full support 10.1 | WebView Android No support No | Chrome Android Full support 61 | Firefox Android Full support 60
|
Opera Android Full support 44 | Safari iOS Full support 10.3 | Samsung Internet Android Full support 8.0 | nodejs ? |
for |
Chrome Full support 1 | Edge Full support 12 | Firefox Full support 1 | IE Full support 3 | Opera Full support Yes | Safari Full support Yes | WebView Android Full support 1 | Chrome Android Full support 18 | Firefox Android Full support 4 | Opera Android Full support Yes | Safari iOS Full support Yes | Samsung Internet Android Full support 1.0 | nodejs Full support Yes |
for await...of
|
Chrome Full support 63 | Edge No support No | Firefox Full support 57 | IE No support No | Opera Full support 50 | Safari Full support 11 | WebView Android Full support 63 | Chrome Android Full support 63 | Firefox Android Full support 57 | Opera Android Full support 46 | Safari iOS ? | Samsung Internet Android Full support 8.0 | nodejs Full support 10.0.0
|
for each...in
|
Chrome No support No | Edge No support No | Firefox No support 1.5 — 57 | IE No support No | Opera No support No | Safari No support No | WebView Android No support No | Chrome Android No support No | Firefox Android No support 4 — 57 | Opera Android No support No | Safari iOS No support No | Samsung Internet Android No support No | nodejs No support No |
for...in |
Chrome Full support 49 | Edge Full support 12 | Firefox Full support 1 | IE Full support 6 | Opera Full support 36 | Safari Full support Yes | WebView Android Full support 49 | Chrome Android Full support 49 | Firefox Android Full support 4 | Opera Android Full support 36 | Safari iOS Full support Yes | Samsung Internet Android Full support 5.0 | nodejs Full support Yes |
for...of |
Chrome Full support 38 | Edge Full support 12 | Firefox Full support 13
|
IE No support No | Opera Full support 25 | Safari Full support 8 | WebView Android Full support 38 | Chrome Android Full support 38 | Firefox Android Full support 14
|
Opera Android Full support 25 | Safari iOS Full support 8 | Samsung Internet Android Full support Yes | nodejs Full support Yes |
function |
Chrome Full support 1 | Edge Full support 12 | Firefox Full support 1 | IE Full support 3 | Opera Full support Yes | Safari Full support Yes | WebView Android Full support 1 | Chrome Android Full support 18 | Firefox Android Full support 4 | Opera Android Full support Yes | Safari iOS Full support Yes | Samsung Internet Android Full support 1.0 | nodejs Full support Yes |
function* |
Chrome Full support 39 | Edge Full support 13 | Firefox Full support 26 | IE No support No | Opera Full support 26 | Safari Full support 10 | WebView Android Full support Yes | Chrome Android Full support 39 | Firefox Android Full support 26 | Opera Android Full support Yes | Safari iOS Full support 10 | Samsung Internet Android Full support 4.0 | nodejs Full support 4.0.0
|
if...else |
Chrome Full support 1 | Edge Full support 12 | Firefox Full support 1 | IE Full support 3 | Opera Full support Yes | Safari Full support Yes | WebView Android Full support 1 | Chrome Android Full support 18 | Firefox Android Full support 4 | Opera Android Full support Yes | Safari iOS Full support Yes | Samsung Internet Android Full support 1.0 | nodejs Full support Yes |
import |
Chrome Full support 61 | Edge Full support 16
|
Firefox Full support 60
|
IE No support No | Opera Full support 47 | Safari Full support 10.1 | WebView Android Full support 61 | Chrome Android Full support 61 | Firefox Android Full support 60
|
Opera Android Full support 44 | Safari iOS Full support 10.3 | Samsung Internet Android Full support 8.0 | nodejs Full support 8.5.0
|
import.meta |
Chrome Full support 64 | Edge No support No | Firefox Full support 62 | IE No support No | Opera Full support 51 | Safari Full support 11.1 | WebView Android Full support 64 | Chrome Android Full support 64 | Firefox Android Full support 62 | Opera Android Full support 47 | Safari iOS Full support 12 | Samsung Internet Android Full support 9.0 | nodejs ? |
label |
Chrome Full support 1 | Edge Full support 12 | Firefox Full support 1 | IE Full support 4 | Opera Full support Yes | Safari Full support Yes | WebView Android Full support 1 | Chrome Android Full support 18 | Firefox Android Full support 4 | Opera Android Full support Yes | Safari iOS Full support Yes | Samsung Internet Android Full support 1.0 | nodejs Full support Yes |
let |
Chrome Full support 49
|
Edge Full support 14
|
Firefox Full support 44
|
IE Partial support 11
|
Opera Full support 17 | Safari Full support 10 | WebView Android Full support 49
|
Chrome Android Full support 49
|
Firefox Android Full support 44
|
Opera Android Full support 18 | Safari iOS Full support 10 | Samsung Internet Android Full support 5.0
|
nodejs Full support 6.0.0 |
return |
Chrome Full support 1 | Edge Full support 12 | Firefox Full support 1 | IE Full support 3 | Opera Full support Yes | Safari Full support Yes | WebView Android Full support 1 | Chrome Android Full support 18 | Firefox Android Full support 4 | Opera Android Full support Yes | Safari iOS Full support Yes | Samsung Internet Android Full support 1.0 | nodejs Full support Yes |
switch |
Chrome Full support 1 | Edge Full support 12 | Firefox Full support 1 | IE Full support 4 | Opera Full support Yes | Safari Full support Yes | WebView Android Full support 1 | Chrome Android Full support 18 | Firefox Android Full support 4 | Opera Android Full support Yes | Safari iOS Full support Yes | Samsung Internet Android Full support 1.0 | nodejs Full support Yes |
throw |
Chrome Full support 1 | Edge Full support 12 | Firefox Full support 1 | IE Full support 5 | Opera Full support Yes | Safari Full support Yes | WebView Android Full support 1 | Chrome Android Full support 18 | Firefox Android Full support 4 | Opera Android Full support Yes | Safari iOS Full support Yes | Samsung Internet Android Full support 1.0 | nodejs Full support Yes |
try...catch |
Chrome Full support 1 | Edge Full support 12 | Firefox Full support 1 | IE Full support 5 | Opera Full support Yes | Safari Full support Yes | WebView Android Full support 1 | Chrome Android Full support 18 | Firefox Android Full support 4 | Opera Android Full support Yes | Safari iOS Full support Yes | Samsung Internet Android Full support 1.0 | nodejs Full support Yes |
var |
Chrome Full support 1 | Edge Full support 12 | Firefox Full support 1 | IE Full support 3 | Opera Full support Yes | Safari Full support Yes | WebView Android Full support 1 | Chrome Android Full support 18 | Firefox Android Full support 4 | Opera Android Full support Yes | Safari iOS Full support Yes | Samsung Internet Android Full support 1.0 | nodejs Full support Yes |
while |
Chrome Full support 1 | Edge Full support 12 | Firefox Full support 1 | IE Full support 3 | Opera Full support Yes | Safari Full support Yes | WebView Android Full support 1 | Chrome Android Full support 18 | Firefox Android Full support 4 | Opera Android Full support Yes | Safari iOS Full support Yes | Samsung Internet Android Full support 1.0 | nodejs Full support Yes |
with
|
Chrome Full support 1 | Edge Full support 12 | Firefox Full support 1 | IE Full support 3 | Opera Full support Yes | Safari Full support Yes | WebView Android Full support 1 | Chrome Android Full support 18 | Firefox Android Full support 4 | Opera Android Full support Yes | Safari iOS Full support Yes | Samsung Internet Android Full support 1.0 | nodejs Full support Yes |
Legend
- Full support
- Full support
- Partial support
- Partial support
- No support
- No support
- Compatibility unknown
- Compatibility unknown
- Experimental. Expect behavior to change in the future.
- Experimental. Expect behavior to change in the future.
- Non-standard. Expect poor cross-browser support.
- Non-standard. Expect poor cross-browser support.
- Deprecated. Not for use in new websites.
- Deprecated. Not for use in new websites.
- See implementation notes.
- See implementation notes.
- User must explicitly enable this feature.
- User must explicitly enable this feature.