A detailed description of the var keyword

Source: Internet
Author: User

var in many languages are more common, in the end what is Var, how to apply, the following is the author's Common JavaScript, C # for VAR description:

var is shorthand for variable (variables, variable). In a variety of computer programming languages, VAR is used as a keyword to define variables, and it can be seen in some operating systems.

    • Javascript
varA=Ten;//correctA=Ten;//correctin JavaScript, both of these methods are the correct way to define variables. This is explained in Microsoft's Script56.chm: Although not secure, it is legitimate to omit the Var keyword from the declaration statement. At this point, the JScript interpreter gives the variable global scope visibility. When a variable is declared at the procedure level, it cannot be used for global scope, in which case the variable declaration must use the VAR keyword. From the above description, the two definition methods are treated to distinguish between the following two cases: ⒈ in a process level (that is, within the definition of a function, whether it is functions, or classes) anywhere, including in a block ( for, while,if... ), when defining a variable, using the var definition, this variable only works at the process level, and vice versa, as a global variable. ⒉ when defining variables outside the procedure level, a global variable is defined regardless of whether or not to ignore var. From this point of view, JS and other languages have a different place, the scope of the variable is not "{}" as the boundary, but to"function () {}"as a boundary, and it is easy to define global variables within the process. If you do not pay attention to this problem, it is easy to produce unpredictable errors. For the use of Var, my advice is to develop good habits: ⒈ at the beginning of the program, define global variables uniformly, ⒉ all variables are defined with Var;⒊ try not to use the same variable name in different procedures. 
    • C#
3.0= "ABCD" form, not the following form:var= "ABCD"; ⒉ once initialization is complete, it is no longer possible to assign values that differ from the initialization value type to the variable. ⒊var requirements are local variables. ⒋ using var to define variables is different from object, which is exactly the same as defining variables in terms of efficiency and using strongly typed methods. 

A detailed description of the var keyword

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.