If statement:
Note: For expressions in parentheses in the IF statement, JS automatically calls the Boolean () transformation function to convert the result of the expression to a Boolean value, and if True executes the code snippet in the statement block
var userscore = 100//The first form: If the statement block has only one sentence, you can omit {}if (Userscore >) console.log ("Your score level is a.") Second form: If the statement block has more than one sentence, you can include {}if (Userscore > +) {console.log ("Your score level is A.")} else if (Userscore >) {console.log ("Your score level is B.")} else if (Userscore >) {console.log ("Your score level is C")}else if (Userscore >) {console.log ("Your score Level was D ")}else {Console.log (" Your score level is F ")}
Switch statement:
Description: The switch statement is a multiple-condition judgment, used for comparison of multiple values equal, but note must break each branch, in fact, you can use if to completely replace
var isActive = 0switch (isActive) {//equals the equivalent of an if statement, supports multiple case equivalents, but never forgets the break case 0:console.log ("inactive") Break Case 1:console.log ("activated State") Break//is equivalent to else in the IF statement, otherwise, do not forget to break default: Console.log ("Unknown State") Break}
Do While statement:
Description: The Do...while statement is a looping statement that runs after the judgment, meaning that the loop body is run at least once, regardless of whether the condition is satisfied
var count = 0do {count++ console.log (count)} while (COUNT<10)
While statement:
Note: While statement is a kind of first judgment, after running the loop statement, must meet the conditions to run the loop body
var count = 0while (Count <) {count++ Console.log (count)}
For statement:
Description: The For statement is also a loop statement that runs after the first judgment, but it has the ability to initialize variables and define loops before executing the loop
for (var i=1; i<=9; i++) {var curline = "for (var j=1; j<=i; J + +) {CurLine + = i + ' x ' + j + ' = ' + I*j + ' \ t '} console.log (CurLine + ' \ n ')}
Note: The order of execution for the For loop is the first step var i=1, the second step i<=9, the third step in the contents of the loop body, the fourth step i++, fifth step i<=9, the sixth step of the body inside the content, and so on, this must understand
For: In statement:
Description: The for...in statement is an accurate iterative statement that is often used to enumerate the properties of an object and then get the property value
var userInfo = {userName: "Li full", userage:25, Usersex: "Male"}for (key in UserInfo) {Console.log (key, '-a ', US Erinfo[key])}
Break and Continue statements:
Description: The break and continue statements are used to precisely control the execution of the code in the loop, where the break statement exits the loop immediately, forcing the execution of the statement following the loop body, while the continue statement exits the current loop, continuing the subsequent loop
For (Var i=1, i<9; i++) {if (i%2==0) continue Console.log (i)}console.log ('---------') for (var i=1; i<9; i++) { if (i%2==0) break Console.log (i)}
With statement:
Description: The WITH statement is used to set the scope of the code to a specific object, and you can refer to any property of the object in the code block
var userInfo = {userName: "Li full", userage:25, Usersex: "Male"}with (userInfo) {//can directly refer to any property of the object var name = Use Rname, age = userage, sex = Usersex Console.log (name, age, Sex)}
This article is from the "ζ Automated operation and maintenance development Road ζ" blog, please be sure to keep this source http://xmdevops.blog.51cto.com/11144840/1846124
Website front-end _javascript.0006.javascript Process Control