[JavaScript] variable conflicts can be compiled using javascript.

Source: Internet
Author: User

[JavaScript] variable conflicts can be compiled using javascript.

In JavaScript, the following code is a valid program:

Var I = 0; var I = 1; alert (I );

The running result is pop-up window output 1,

It seems that there is no problem at all. However, in some programming languages such as Java and C, the following similar code is not a legal program:

Int I = 0; int I = 0;

Compilation fails. What's more, how about running it? Because variable I is repeatedly defined, and in JavaScript, even if variable I is repeatedly defined, there is no problem. This is the problem of static scope and dynamic scope. Static scope and dynamic scope are specific. Here we will not put the concept in a large section of compilation principles on a large scale, so we will feel dizzy.

In Javascript, even if variable I is repeatedly defined, there is no problem. Even if variable conflicts can also be compiled, what is the problem?

The problem is very big. As a result, errors in the following program are hard to be found:

For (var I = 0; I <1; I ++) {for (var I = 0; I <1; I ++ ){}}

In some programming languages such as Java and C, a prompt is displayed that variable I is repeatedly defined, because the calculated variable I in for should be written as j or another, but Javascript will not, after your webpage is opened, it will not be displayed below the browser: Then you will find that the special effects you need cannot be properly killed. Especially in the context of today's world-wide code, it is difficult for you to find that the code you write, conflict with the copied code.

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.