In this article
Previous versions of JScript did not require explicit declaration of variables. Although this feature saves keystrokes for programmers, it also makes it difficult to trace errors. For example, you could assign a value to a misspelled variable name, which would neither generate an error nor return the desired result. Furthermore, undeclared variables have global scope, which can cause additional confusion. So where previously you could write script code such as
codes = f("q1").categories();for(i=0;i<codes.length;i++) { <some statements…> }you must now declare the variables with the var keyword:
var codes = f("q1").categories();for(var i=0;i<codes.length;i++) { <some statements…> }This will still not explicitly declare the type of the variable: It may change type later as a result of an assignment. In addition to this "loose typing", JScript .NET can now be a strongly typed language. JScript .NET provides more flexibility than previous versions of JScript by allowing variables to be type annotated. This binds a variable to a particular data type, and the variable can store only data of that type. Although type annotation is not required, using it helps prevent errors associated with accidentally storing the wrong data in a variable and can increase program execution speed.
In addition to this explicit type declaration, a technology called "implicit type inferencing" is introduced. Type inferencing analyzes your use of variables in the script code and infers the type of the variable for you. This means that you can achieve considerable improvements in speed using scripts also when you do not specify the type of your variables, as long as your variables are not changing type.