Getting started with JavaScript: 005-Basic JS statements

Source: Internet
Author: User

Getting started with JavaScript: 005-Basic JS statements
The basic statements of JS are as follows. Let's take a look at the loop statements and selection statements.
Loop statement
1. for Loop

For (var I = 1; I <100; I ++) {// code}
2. do... while loop
Var I = 0; do {I ++; // code} while (I <100 );
3. Traverse
Var array = new Array (); array [0] = "you know"; array [1] = "over"; array [2] = "Haha "; array [3] = "Tigger"; for (var item in array) {document. write (item );}
Since it is a loop, the break and continue are naturally the same.
    for (var i = 1; i < 100; i++) {        if (i == 99) {            break;        }        if (i % 2 == 0) {            continue;        }        alert(i.toString());    }

Select statement
1. if... else
This is too simple.
2. switch
It is used in the same way as other languages.
    var flag = "";    switch (flag) {        case 1:            break;        case 2:            break;        default:            alert(flag);            break;    }
These statements are basically the same as the programming languages we usually use. The definitions, declarations, and assignments of variables are the same.

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.