Home >Web Front-end >JS Tutorial >Summary of two methods of writing multiple statements into one statement in js_javascript skills

Summary of two methods of writing multiple statements into one statement in js_javascript skills

WBOY
WBOYOriginal
2016-05-16 19:07:231228browse

Summary of two methods of writing multiple statements into one statement in Javascript
1. Use the comma operator to write multiple statements into one statement
1. Declare multiple variables at one time
var i=1,j=1,k=1
2. Separate multiple statements with commas
i=1,j=i 2,k=j 2
2. Use curly braces to separate Multiple statements are written as one statement
If statement, while statement, do/while statement, for statement, for/in statement and function statement can only be followed by one sub-statement. In this case, { and } Surround multiple statements into one statement.

Copy code The code is as follows:

if(username==null)
username = "guest";
login = true;

In the above example, "login = true;" is not a sub-statement of the if statement. To make it also a sub-statement of the if statement, you must use Curly brackets:
Copy code The code is as follows:

if(username==null)
{
username = "guest";
login = true;
}
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn