Javascript tips: 0---2 and 0---2

Source: Internet
Author: User
Tags javascript array

Javascript tips: 0---2 and 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 total9Control statements:

  • If statement
  • Do-while statement
  • While statement
  • For statement
  • For-in statement
  • Label statement
  • Break and continue statements
  • With statement
  • Switch statement
The following is an example of these control statements:

Var I = 10; if (I> 15) {alert ("I> 15")} else if (I <0) {alert ("I <0 ")} else {alert ("0 <I <15")} // The if statement is very simple, that is, to make a condition judgment, correctly execute this code and incorrectly execute another piece of code

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 <count; I ++) {alert (I)} // for is a type of pretest loop statement, however, unlike while, it has the ability to initialize variables and define code to be executed after a loop is executed.

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 <count; I ++) {alert (I) ;}// the label statement can be added to the Code.

// 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:
  • Basic Data Type in js undefined null boolean number string
  • Javascript is a complex data type object. It is the basic type of all objects.
  • Like other languages, js has nine basic control statements.
  • The function in js does not need to specify the return value. In fact, the function that does not specify the return value returns undefined.
  • Parameters in js can be passed at will. Note that the arguments [] array helps you
  • Functions in js cannot be overloaded, but you can imitate them.
The following section describes how to learn about variable scope memory garbage collection in JS.
Javascript Learning Method

Javascript is very similar to C.
The following is a brief description of the difference between C and C.
1. Call in HTML
<Script language = "JavaScript" src = xxx. js> </script> src this is a javascript script written when an external js script is called.
2. Variable Declaration
Var variable name = variable value;
Of course, single quotation marks or double quotation marks must be added for string type.
3. function declaration
Function Name (parameter 1, parameter 2 ...)
{
Return value;
}
4. One more operator than C >>>
>>> This is the right shift (0-all) of other C, but it does not have the three-object operator.
Other loops and branches are the same.
You should see that the event handle, the Document object in the object, the Windows object, the javascript array, the built-in functions and methods are basically enough.
Finally, we recommend that you use JavaScript,. A. Beginner's. Guide, and. Third. Edition in English.
Chinese version: javascript programming started

How to Learn Javascript

We recommend a book, JavaScript advanced programming. This book may be more suitable for you than the rhino book.
 

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.