May 06, 2021 JavaScript
The command issued by the JavaScript statement to the browser. The function of a statement is to tell the browser what to do.
The JavaScript statement is a command sent to the browser.
The role of these commands is to tell the browser what to do.
The following JavaScript statement outputs the text "Hello Dolly" to the HTML element of id"demo":
A sign is used to separate JavaScript statements.
Usually we add a sign at the end of each executable statement.
Another use in using a half sign is to write multiple statements in a row.
Is the same as writing:
You may also see cases without a sign.
In JavaScript, it is optional to end a statement with a sign. |
JavaScript code is a sequence of JavaScript statements.
The browser executes each statement in the order in which it was written.
This example outputs a title and two paragraphs to a Web page:
JavaScript can be combined in batches.
The block of code starts with an opening brace and ends with a closing brace.
The function of a block of code is to execute a sequence of statements together.
This example outputs a title and two paragraphs to a Web page:
You'll learn more about functions in a later section.
JavaScript statements typically start with a statement identifier and execute the statement.
Statement identifiers are reserved keywords that cannot be used as variable names.
The following table lists JavaScript statement identifiers (keywords):
Statement | Describe |
---|---|
break | Used to jump out of a loop. |
Catch | Statement block, which executes catch statement blocks when an error is made in the execution of the try statement block. |
continue | Skip an iteration in the loop. |
do ... while | Executes a statement block that continues when the conditional statement is true. |
for | When the conditional statement is true, you can execute the block of code a specified number of times. |
for ... in | A property used to traverse an array or object (looping through the properties of an array or object). |
function | Define a function |
if ... else | Used to perform different actions based on different conditions. |
return | Exit the function |
switch | Used to perform different actions based on different conditions. |
throw | Throw (build) an error. |
try | Implement error handling, which is used with catch. |
Var | Declare a variable. |
while | When the conditional statement is true, the statement block is executed. |
JavaScript ignores extra spaces. Y ou can add spaces to your script to improve its readability. The following two lines of code are equivalent:
You can use backslashes in text strings to line lines of code. The following example shows correctly:
However, you can't fold a line like this:
JavaScript comment statement action
Practice commenting statements in JavaScript, and the commented blocks of code will not be run in JavaScript.