Javascript Learning Guide 0---2

Source: Internet
Author: User

Javascript Learning Guide 0---2

Okay. Pretty girls have read it. Let's continue with the content of the last lecture (the content of the previous section)

Control statement:

First, I would like to sum up a total9 <喎?http: www.bkjia.com kf ware vc " target="_blank" class="keylink"> Expires/expires + CgogaWYg0 ++ expires/Cw + bAtLfWsfDOqtXivLi49r/Y1sbT777kvtm49sD919MKPHA + expires = "brush: java;"> var I = 10; if (I> 15) {alert ("I> 15")} else if (I <0) {alert ("I <0")} else {alert ("0 ")

Var I = 0; do {I + = 2} while (I <10); alert (I); // the do-while statement is a post-test loop statement, that is to say, if the condition statement is not met, the loop statement will continue to be executed until it is met after the loop body code is executed.

Var I = 0; while (I <10) {I + = 2} alert (I); // opposite to the do-while statement above, the while statement is a loop statement of the previous test. You must first judge whether the expression characters in the while statement do not match.

Var count = 10; for (var I = 0; I
  
   
For (var p in window) {console. log (p) ;}// for-in iteration statements are generally used to enumerate all the properties of the WINDOW object.

CSDN: for (var I = 0; I
    
     
// For break and continue statements, the break statement immediately exits the loop and forces the statement after the loop. Although the continue statement also exits the loop, it continues to execute var num = 0 from the top of the loop; for (var I = 0; I <10; I ++) {if (I % 5 = 0) {break; // replace it with continue.} num ++ ;} alert (num );

// With statement is mainly used to simplify the compilation of the same object. with (location) {var c = hostname/location. hostname var s = url // location. url}

// The Last switch statement var I = 0 // try these numbers 1, 2, 3 switch (I) {case 0: alert ("0"); break; case 1: alert ("1"); break; case 2: alert ("2"); break; case 3: alert ("3"); break ;}

Although these statements are simple, they do build the foundation of a huge application, so don't underestimate them!


Function:

Functions are important to any language. Let's take a look at the functions in JS.

Function hellocsdn (param1, param2) {alert ("hello" + param1 + "," + param2) ;}// this function can call hellocsdn (csdn, nice) through the function name ); // The output result is hello csdn, nice; // functions in js are relatively developed. You can specify or do not specify whether function csdn (a, B) {return a + B is returned; alert ("will pop up") // will it pop up ?} Alert (csdn (cs, dn); // the above Code will pop up CSDN words, but the pop-up code in the code will never be executed

Understanding of function parameters:

You only need to remember that you do not have to pass in the parameter when calling this function, the preceding hellocsdn function has two parameters: param1 and param2. When you call hellocsdn, you can choose not to upload one or only one, or you can upload both of them, but I would like to remind you that when you do not upload it, the parser will assign it undefined by default. Remember this.

There is also a tool for introducing function parameters to arguments [? ] Arguments is a simple array object. Yes, it stores the parameters in the function. In the hellocsdn function, arguments [0] Is param1, and arguments [1] is param2!

The last point I want to talk about is that there is no overload in js functions. If there are two functions with the same name but different parameters, the subsequent functions will overwrite the previous functions.


Summary: in JavaScript, the basic data type undefined null boolean number stringjs is a complex data type object. It is the basic type of all objects. js, like other languages, has nine basic control statements. Functions in js do not need to be used. specify the return value, in fact, parameters in undefinedjs returned by a function that does not specify a returned value can be passed at will. Note that arguments [] array can help your js function to be reloaded, but you can imitate it. The following section describes how to learn about variable scope memory garbage collection in JS.

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.