You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A variable declaration introduces a variable with the given name in the containing declaration space. The type associated with a variable is determined as follows:
· If the declaration includes a type annotation, the stated type becomes the type of the variable. If an initializer is present, the initializer expression is contextually typed (section 4.19) by the stated type and must be assignable to the stated type, or otherwise a compile-time error occurs.
· If the declaration includes an initializer but no type annotation, and if the initializer doesn’t directly or indirectly reference the variable, the widened type (section 3.9) of the initializer expression becomes the type of the property. If the initializer directly or indirectly references the variable, the type of the variable becomes the Any type.
· If the declaration includes neither a type annotation nor an initializer, the type of the variable becomes the Any type.
The second bullet covers cases like:
varx=x;
but not cases like the initial example with no initializer.
The text was updated successfully, but these errors were encountered:
In section 5.1 Variable Statements we say:
The second bullet covers cases like:
but not cases like the initial example with no initializer.
The text was updated successfully, but these errors were encountered: