JavaScript Intensive Tutorial--statement

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.