inspired by the question int a[] = {1,2,}; Weird comma allowed. Any particular reason? I remembered a question concerning the syntax in Adobe's Actionscript.
For some reason it is possible (at least in Flex 3) to assign a value to a variable before it was declared:
public function foo() : void {
a = 3;
var a : int = 0;
}
Does this make any sense..? Is this a bug in the Adobe FlexBuilder compiler? Or is this due to maybe some legacy to older Ecmascript editions?
An interesting implication of the lack of block-level scope is that you can read or write to a variable before it is declared, as long as it is declared before the function ends. This is because of a technique called hoisting , which means that the compiler moves all variable declarations to the top of the function. For example, the following code compiles even though the initial trace() function for the num variable happens before the num variable is declared...
Actionscript 3.0 Docs - Variables (quote found about 2/3 down the page)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With