Relationship and influence between function declaration, variable declaration and variable assignment in JavaScript

Source: Internet
Author: User

Relationship and influence between function declaration, variable declaration and variable assignment in JavaScript

There are several common understandings between function declarations, variable declarations, and variable assignments:
1. All global variables are properties of window
2. The function declaration is promoted to the top of the range scope
3. Variable declarations are promoted to the top of the range scope
4, the variable declaration is higher precedence than the function declaration, the variable declaration takes precedence over the function declaration is promoted, if both the same name exists simultaneously, the promoted function declaration overrides the first promoted variable declaration
5, the variable assignment will not be promoted, until the execution of the line code to start assigning values

Add:

6, the entire process of invoking JavaScript functions can be divided into the pre-compilation period (also called the Declaration period) and the assignment period (also known as the calculation of the execution period).

预编译期完成对所有变量(包括形参、函数内部参数)和函数的声明,赋值期又可以分为两个阶段,函数花括号内语句执行前后,执行前完成对形参置和函数的赋值,执行后按照语句顺序执行赋值。

For example:

function test(msg){    var msg ; alert(msg);//弹出:test方法测试,因为先完成所有变量的声明,然后在对形参赋值}test("test方法测试");

The summary and test code of the above content can be viewed:
http://ju.outofmemory.cn/entry/4646
Original: http://dmitry.baranovskiy.com/post/91403200

Relationship and influence between function declaration, variable declaration and variable assignment in JavaScript

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.