ECMAScript Study Notes

Source: Internet
Author: User

1. ECMAScript does not have a block-level scope, so variables defined inside the loop are also accessible outside the loop
eg
var count = 10;
FPR (var i=0; i<count; i++) {
alert (i);
}
alert (i); 10

2. The function of ECMAScript can define any parameter, and the two parameters can not correspond to any parameter.
The arguments passed in when the function is called are stored in arguments[], and the parameters that are written when the function is defined correspond to the corresponding parameters in arguments[].
The length of arguments[] is determined by the parameters passed in when the function is called
When there is a corresponding relationship between the two, modify any one of the values, the other will also change

eg
function Showarguments (num1,num2,num3) {
num2 = 10;
ARGUMENTS[2] = 100;
Console.log (num1+ ' +num2+ ' +num3+ ': ' +arguments[0]+ ' +arguments[1]+ ' +arguments[2]);
}

Showarguments (); "Undefined undefined:undefined undefined 100"
Showarguments (1); "1 undefined:1 undefined 100"
Showarguments (a); "1 undefined:1 10 100"
Showarguments (1,1,1); "1 10 100:1 10 100"
Showarguments (1,1,1,1); "1 10 100:1 10 100"

2. The parameters of all functions of ECMAScript are passed by value, and the values of the parameters of the call are paid to the parameters inside the function.
(PS: When a parameter is a basic data type, the function does not change the value of the external parameter;
However, when the parameter is a reference data type, because the external and internal parameters point to the same memory area,
After the object is changed within a function, the object is also changed after it is accessed elsewhere,
However, the same value that changes the parameter within the function points to another address, and still does not affect the value of the external parameter.
eg
var obj = new Object ();

function SetName (obj) {
Obj.name = "Regis";
}

function Settitle (obj) {
Obj.title = "King of Lucis";
obj = new Object ();
Obj.title = "Nilheim";
}
SetName (obj);
Settitle (obj);
Console.log (Obj.name); "Regis"
Console.log (Obj.title)//"King of Lucis"

Iteration method for array type in 3.ECMAScript
A.every (function (Item,index,array) {}): Runs the given function for each item in the array, and returns True if the function returns true for each item.
B.some (function (Item,index,array) {}): Runs the given function for each item in the array, and returns True if the function returns true for either item.
C.filter (function (Item,index,array) {}): Runs the given function for each item in the array, returning a list of the items that the function returns True.
D.foreach (function (Item,index,array) {}): Runs the given function for each item in the array. The method has no return value
E.map (function (Item,index,array) {}): Runs the given function for each item in the array, returning a set of the results of each function call.

ECMAScript Study Notes

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.