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