if i don’t specifically type a variable in my code will it compile as a default datatype? for example, the “for each … in” function works best without typing the variable:
for each (var element in myArray)
{
//process each element
}
does my element variable have a datatype? if it is typed as Object is it better to actually write element:Object or does it matter?
EDIT
actually, that was a bad example, since the element variable is going to be typed to whatever element is in myArray.
but is that how it works if a variable is untyped? it will simply become what is passed to it?
here’s a better example for my question:
var a = "i'm a string"; //does this var becomes a String?
var b = 50.98; //does this var becomes a Number?
var c = 2; //does this var becomes an int?
The
elementvariable doesn’t have any data type – it is untyped and thus can hold anything.And yeah, it is equivalent to writing
element:Objectorelement:*, but it is always advisable to type your variables – this will help you catch some errors before you run the code. The mxmlc compiler will emit a warning if you don’t do this, which can be fixed by typing it ase:Objectore:*.