JavaScript Basics-function declarations, scope chains of functions

Source: Internet
Author: User
function declaration and function Expression difference

A function declaration declares a function by the function name () {}

A function expression is declared by declaring a variable and then assigning a function.

The difference is that before the execution of the program, the function declares the function to obtain the declaration of the variable, where the declaration of the variable is just a space, and then give a name, then to the variable name assignment value, there is a value, that is, before the assignment of the variable is not obtained, Using this variable will get undefined.

Regardless of whether you put the function in the program at the beginning or the end, the function of the execution of the statement can be normal execution.

FN ();//output FN
Console.log (FN2);//undefined declared, no value, automatic assignment undefined
function fn () {console.log (' fn ')}//functions Declaration
var fn2 = function () {console.log (' fn2 ')};//functional expression
FN2 ();//Output FN2

Declaration predecessors of variables and declarations of functions

There is an answer to the question above.

What is arguments?

Arguments is an object inside a function that corresponds to a passed in parameter, is a class array object, and does not have a method to manipulate the array.

Each pass-in parameter corresponds to ARGUMENTS[0],ARGUMENTS[1], which has a sequence of points.

such as function fn (name,age) {

Console.log (arguments[0];);

Console.log (arguments[1];);

}

Overloading of functions in JavaScript?

There is no function overload in JavaScript, because the same function name, if you define a different number of parameters, will overwrite the first occurrence.

Therefore, through the internal access to the arguments can not be passed in the number of parameters, although access can be, but the parameters passed in successively.

What is an immediate execution function expression, and what is the effect?

What is the scope chain for a function?

JavaScript Basics-function declarations, scope chains of functions

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.