JS---Name of function and variable name

Source: Internet
Author: User

Continue to the scope of the problem, I saw this morning for a while, afternoon saw another type of question, function name and variable name the same problem. There will be no conflict between the name of the function and the name of the variable. And I haven't tested it. Lazy. Direct Sticker Code:

What do you guess the result after running? Breath: 100!! I really am a good tone, without thinking directly to give the answer, it is not very good habits.

Unexpected error, a little confused feeling. But one step at a way to analyze it, you can understand why this is the answer.

First, the problem needs to be linked to the pre-compilation phase of JS, that is, the context that needs to be prepared before executing the code, and the variables, functions, and other resources that need to be prepared during the precompilation phase.

Variables and variable expressions are declared at the pre-compilation stage, and are not assigned, and get undefined;

The declarative function gets the assignment at the pre-compilation stage, yes, it is directly assigned to the value.

and the order of preparation resources is sequential, pre-compiled function, parameters > variables;

Then this problem can be resolved as:

This time can be a good understanding of why a () This result is an error said a is not a function, people are already not function, has been redefined assignment value type, of course, to error.

JS---Name of function and variable name

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.