English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
A JavaScript application is composed of statements with proper grammar.
JavaScript statements are "instructions" that web browsers need to "execute".
A statement can span multiple lines.
If each statement is separated by a semicolon, multiple statements may appear on one line.
This statement tells the browser to write "Hello world" inside the HTML element with id="para":
document.getElementById("para").innerHTML = "Hello world";Test to see‹/›
You can find in ourIn the JavaScript statements tutorialLearn more about statements.
The following is a list of JavaScript statements and declarations listed by category:
Declaration | Description |
---|---|
var | Declare a variable, which can optionally be initialized with a value |
let | Declare a block {} scoped local variable, which can optionally be initialized with a value |
const | Declare a read-only named constant |
Statement | Description |
---|---|
break | Terminate the current loop, switch, or label statement, and pass control to the statement after the terminating statement. |
continue | Terminate the execution of a statement in the current loop or the current iteration of a labeled loop, and continue executing the loop in the next iteration. |
if...else | If the specified condition is true, execute a statement. If the condition is false, another statement can be executed. |
switch | Calculate the expression so that the value of the expression matches the case clause, and execute the statement related to the case |
throw | Throw a user-defined exception |
try...catch | Mark the statement block to be attempted and specify the response when an exception is thrown |
Statement | Description |
---|---|
while | Create a loop that executes the specified statement as long as the computed result of the test condition is true. The condition is checked before the statement is executed |
do...while | Create a loop that executes the specified statement until the value of the test condition is false. The statement is executed first, and then the condition is evaluated, so the specified statement is executed at least once |
for | Create a loop consisting of three optional expressions, enclosed in parentheses and separated by semicolons, followed by the statement to be executed in the loop |
for...in | Traverse the enumerable properties of an object in arbitrary order. For each different property, you can execute a statement |
for...of | Iterate over iterable objects (including arrays, array-like objects, iterators, and generators), call custom iteration hooks, and execute statements for each different property value |