On the modification of JavaScript function parameters _javascript skills

Source: Internet
Author: User

A pen test to think about, usually no one will modify the parameter values inside the function. Here, there are three ways to change the discussion.

1, directly modify the function declaration when the formal parameters

Copy Code code as follows:

Function F1 (a) {
alert (a);
A = 1;//modified parameter A
Alert (1 = = = a);
Alert (1 = = arguments[0]);
}
F1 (10);

Function F1 defines parameter A, calls newsletters parameter 10, pops up 10, modifies a 1, pops up two times true,a and Arguments[0] all 1.

2, through the function inside the arguments object modification

Copy Code code as follows:

function F2 (a) {
alert (a);
Arguments[0] = 1;//Modify Arguments
Alert (1 = = = a);
Alert (1 = = arguments[0]);

}

The effect is F1 with the function.

3, the local variable declared within the function has the same name as the formal parameter

Copy Code code as follows:

Function F3 (a) {
alert (a);
var a = 1;//declares local variable A and assigns a value of 1
Alert (1 = = = a);
Alert (arguments[0]);
}
F3 (10);

Function F3 defines the parameter a, the function declares local variable A at the same time assigns a value of 1, but here's a is still the argument a, from the last ejected Arguments[0] is modified to 1 can prove.

4, if you just declare the local variable a, but do not assign a value, the situation is different

Copy Code code as follows:

Function F3 (a) {
var a;//only declares, does not assign value
alert (a);
Alert (arguments[0]);
}
F3 (10);

This time the pop-up is 10, not undefined.

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.