JavaScript Basics 5

Source: Internet
Author: User

Do not confuse the equality operator (= =) with the assignment operator (=).

If the first of the two conditions separated by the && operator is false, the second condition is not detected as true or false. With this, you can increase the speed of your scripts.

Use multiple conditions with a switch

if (button== "Next") window.location = "next.html";    else if (button== "previous") window.location = "pre.html";    else if (button== "Home") window.location = "home.html";    else if (button== "back") window.location = "back.html";    Switch (Button) {case        "next":            window.location = "next.html";            break;        Case "Previous":            window.location = "pre.html";            break;        Case "Home":            window.location = "home.html";            break;        Case "Back":            window.location = "back.html";            break;    }

You can use multiple statements after each case statement in the switch structure. You don't have to put them in curly braces. If case matches, the JavaScript resolver executes the statement until it encounters a break (or the next).

JavaScript also has a third type of loop. For....in Loop, he is specifically used to perform operations on an object's properties

For (i-navigator) {        document.write ("property:" + i);        document.write ("Value:" + navigator[i] + "<br>");    }

Like the normal for loop, this type of loop also uses an index variable. In each iteration of the loop, the variable is set to the next property of the object. This makes it easy to examine and modify each property of an object.

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.