Summary Tenth Day

Source: Internet
Author: User

Today learned the array and function, more difficult to learn is the function, the teacher said quite simple is not how to use, as long as more use on the line, and this function will be used in PHP.

To create an array:

Format: var variable name = [array element 1, array element 2]

The length of the array:

Method: Array variable name. length

Use the new keyword and the array () method to create

Format: var array variable name = new Array ();

To iterate over an array element:

Format: var arr = [];

for (var i=0;i< array length; i++) {

Arr[i];

}

For....in statements can also iterate over an array

Format: for (variable name in array name) {

Creation of multidimensional arrays:

Format: array variable name [subscript of one-dimensional array] [subscript of two-dimensional array element];

Function:

what does a function do?

Code reuse

Modular programming---Object-oriented programming!

Register module, Login module

To define a function:

Format: Function name (parameter 1, parameter 2, parameter n) {

function body

}

calling Function: format: function name ()

Parameters can have more than one!

return keyword:

Return is the meaning of "back"! Return it is written in the function body!

1. When the function body encounters the return keyword, then the code below it stops executing! Just jump out of the function!

2. The main function of the return keyword is to return the data to the caller of the function! The concept of the return value!

In a function either output or return but we define the function to return the result using return!

Call Method: Alert (function name (parameter)), out of the warning window display;

document.write (function name (parameter)), displayed on the Web page

Anonymous functions:

A variable is any data type that can be stored!

Variables can also store functions!

How to call:

Format: (function () {}) ()

Scope of the variable:

Variables defined outside of the function its scope is global!

The variables defined inside the function are local and can only be used within the function!

Promote the scope of the variables defined inside the function to the global scope:

Just need to remove the var keyword of the variable defined inside the function, then the scope of the variable is global!

When you remove the Var in front of the variable name in the function, declare a variable with the same name outside the function!

Summary Tenth Day

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.