JavaScript statement parsing

Time:2019-10-9

In HTML, JavaScript statements are “instructions” executed by web browsers.

Example

Var x, y, z;//statement 1
X = 22; // statement 2
Y = 11; // statement 3
Z = x + y; // statement 4

JavaScript program

Computer programs are a series of “instructions” that are “executed” by a computer.

In programming languages, these programming instructions are called statements.

JavaScript programs are a series of programming statements.

Note: In HTML, JavaScript programs are executed by web browsers.

JavaScript statement

JavaScript statements consist of the following components:

Values, operators, expressions, keywords, and annotations.

This statement tells the browser to output “Hello Kitty.” in the HTML element id= “demo”:

Example

document.getElementById("demo").innerHTML = "Hello Kitty.";

Most JavaScript programs contain many JavaScript statements.

These statements are executed one by one in the order in which they are written.

Note: JavaScript programs (and JavaScript statements) are often referred to as JavaScript code.

Semi-colon;

Semiconductors separate JavaScript statements.

Please add a semicolon after each executable statement:

a = 5;
b = 6;
c = a + b;

You may see examples of no semicolons on the Internet.

Tip: It’s not necessary to end a statement with a semicolon, but we still urge you to do so.

JavaScript blank characters

JavaScript ignores multiple spaces. You can add spaces to scripts to enhance readability.

The following two lines are equal:

var person = "Bill";
var person="Bill"; 

It is a good habit to add spaces next to operators (=+ – */):

var x = y + z;

JavaScript line length and fold

In order to achieve the best readability, programmers often like to control lines of code within 80 characters.

If a JavaScript statement is too long, the best place to fold it is an operator:

Example

document.getElementById("demo").innerHTML =
 "Hello Kitty.";

JavaScript code block

JavaScript statements can be bracketed({…}) Combine in blocks of code.

The function of a code block is to define statements that are executed together.

You will see statements grouped together in blocks in JavaScript:

function myFunction() {
    document.getElementById("demo").innerHTML = "Hello Kitty.";
    document.getElementById("myDIV").innerHTML = "How are you?";
}

JavaScript keywords

JavaScript statements often use a keyword to identify JavaScript actions that need to be performed.

The following table lists some of the key words that will be learned in the course:

Key word describe
break Stop switch or loop.
continue Jump out of the loop and start at the top.
debugger Stop executing JavaScript and call the debugging function (if available).
do … while Execute the statement block and repeat the code block if the condition is true.
for Mark the block of statements that need to be executed as long as the condition is true.
function Declare functions.
if … else Mark the block of statements that need to be executed, depending on a condition.
return Exit the function.
switch Mark the block of statements that need to be executed, depending on the situation.
try … catch Implement error handling for statement blocks.
var Declare variables.

Note: JavaScript keywords refer to reserved words. Reserved words cannot be used as variable names.

Source: www.sysoft.net.cn

Recommended Today

Summary of Android development of Dajiang UAV — video decoding

DJI Mobile SDK is a development interface provided by Dajiang for developers to develop UAV applications, which can realize the control of UAV flight and complete some visual tasks with UAV cameras. At present, online development courses mainly focus onDJI developer communityThere are very few resources on the Internet. Don’t talk too much. Now I’ll […]