The difference between using Var and omitting Var to define variables in JS

Source: Internet
Author: User

When defining variables in JS, we are used to using Var, in fact, omitting Var can also be used.

To summarize today, use Var or omit Var to define the difference between variables 1, var private variable, can only be used in the current JS, or in the current scope to use, define private variables, can not delete;2, omit var definition variables, such as a = "SSS", defined a global variable object A, A is not deleted before the delete, we can directly in the browser console input A can see the results, in any one JS can call this object, you can choose Delete.  It is not recommended to omit Var, omit Var when you have to carefully omit Var will bring the following: 1. The semantics are not clear. 2. When the team develops, it is easy to overwrite variables in other scopes and throw exceptions. 3. Add unnecessary members to the Window object, that is, to bring unnecessary pollution to the window, so use the best by the way delete, so as not to affect other variables

The difference between using Var and omitting Var to define variables in JS

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.