This article is the official HTML5 training course for h5edu institutions, mainly introduces: JavaScript intensive tutorial--statement
Conditional statements
Often when writing code, you always need to perform different actions for different decisions. You can use conditional statements in your code to accomplish this task.
In JavaScript, we can use the following conditional statements:
If statement-use this statement to execute code only if the specified condition is true
If...else Statement-executes code when the condition is true and executes other code when the condition is false
If...else If....else Statement-Use this statement to select one of several code blocks to execute
Switch statement-Use this statement to select one of several code blocks to execute
JavaScript switch Statement Use the switch statement to select one of several code blocks to execute. Syntax switch (n) {Case 1: executing code block 1 break;case 2: executing code block 2 break;default: N code that executes when different from 1 and 2
Default keyword
Use the default keyword to specify what to do when a match does not exist:
var day=new Date (). GetDay (); switch (day) {case 6: x= "Today it ' s Saturday"; Break;case 0: x= "Today it ' s Sunday"; Break;default: x= "Looking forward to the Weekend";}
Different types of loops
JavaScript supports different types of loops:
For-loop code block for a certain number of times
For/in-Looping through the properties of an object
While-loops the specified block of code when the specified condition is true
Do/while-also loops the specified block of code when the specified condition is true
The break statement is used to jump out of a loop.
The Continue is used to skip an iteration in the loop.
Click to enter JavaScript Intensive tutorial: http://www.h5edu.cn/htm/step/h5edu_44.html
JavaScript Intensive Tutorial--statement