The declaration of a JavaScript function object (@ INCLUDES function declaration and function expression)

Source: Internet
Author: User

When you usually use JS to write functions, it is generally customary function fn () {} to declare a function, in reading some excellent plug-ins when you see the var fn = function () {} the creation of such functions, exactly what they What is the difference between using it, today in the spirit of breaking the sand pot to ask the end, well say this fascinating--function statement.

function declaration

Function Sound Example code

function fn () {    console.log (' fn function execution: ') );     // Code:}

So we declare a function called FN, and here's a thought, do you think it would be executed to invoke him on top of the function? Or will it be an error?

// before invoking the FN function    we declared function fn () {    console.log (' fn function execution: ') );     // Code:}

Console output Results:

Yes, at this point the FN function can be called, here to summarize the reasons.

1: The fn function is the result of a variable that is stored by default in a global context variable (can be verified by window. Function name)

2: This is a function declaration that is created during the global context stage and is already available in the code execution phase. Ps:javascript initializes the context (by global → Local) Each time the method is entered.

3: It can affect variable objects

The declaration of a JavaScript function object (@ INCLUDES function declaration and function expression)

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.