File tree Expand file tree Collapse file tree 4 files changed +37
-4
lines changed
Expand file tree Collapse file tree 4 files changed +37
-4
lines changed Original file line number Diff line number Diff line change 77[ _ name_ ] ( name.md ) __ |__
88[ _ injected-variable_ ] ( injected_variable.md ) __ |__
99[ _ positional-variable_ ] ( positional_variable.md ) __ |__
10- [ _ variable-declaration _ ] ( variable_declaration .md) __ |__
10+ [ _ variable-initializer _ ] ( variable_initializer .md) __ |__
1111[ _ operator-expression_ ] ( operator_expression.md ) __ |__
1212[ _ if-control-expression_ ] ( if_control_expression.md ) __ |__
1313[ _ while-control-expression_ ] ( while_control_expression.md ) __ |__
Original file line number Diff line number Diff line change 33## Syntax
44
55[ _ expression_statement_ ] ( expression_statement.md ) __ |__
6+ [ _ variable-declaration_ ] ( variable_declaration.md ) __ |__
67[ _ return_ ] ( return.md ) __ |__
78[ _ result_ ] ( result.md ) __ |__
89[ _ yield_ ] ( yield.md ) __ |__
Original file line number Diff line number Diff line change 22
33## Syntax
44
5- [ _ storage_class_ ] ( storage_class.md ) __ ?__ [ _ binding_mode_ ] ( binding_mode.md ) [ _ name_ ] ( name.md ) _ type_declaration_ ** ?**
5+ [ _ storage_class_ ] ( storage_class.md ) __ ?__ [ _ binding_mode_ ] ( binding_mode.md ) [ _ name_ ] ( name.md ) _ type_declaration_ ** ?** ` ; `
66
77## Semantics
88Declares a variable with a [ _ name_ ] ( name.md ) which can be used in the scope or
@@ -14,8 +14,8 @@ Variable declarations may appear in the following contexts:
1414 - In a code block of a control-expression
1515 - In a class declaration.
1616
17- A _ variable_declaration_ is a [ _ expression _ ] ( expression .md) which results in a
18- reference to declared variable .
17+ A _ variable_declaration_ is a [ _ statement _ ] ( statement .md) as it was not assigned a value,
18+ there can be no result .
1919
2020The type and coercion-method of the variable can be set by using the
2121[ _ coerce_ ] ( coerce.md ) operator on the _ variable_declaration_ or on the
Original file line number Diff line number Diff line change 1+ # variable-declaration
2+
3+ ## Syntax
4+
5+ [ _ storage_class_ ] ( storage_class.md ) __ ?__ [ _ binding_mode_ ] ( binding_mode.md ) [ _ name_ ] ( name.md ) _ type_declaration_ ** ?** ( ` = ` | ` += ` ) [ _ expression_ ] ( expression.md )
6+
7+ ## Semantics
8+ Declares a variable with a [ _ name_ ] ( name.md ) which can be used in the scope or
9+ child scopes where the variable is declared; and initializes it.
10+
11+ Variable declarations may appear in the following contexts:
12+ - In global scope.
13+ - In a function or lambda.
14+ - In a code block of a control-expression
15+ - In a class declaration.
16+ - In an expression.
17+
18+ A _ variable_initializer_ is a [ _ expression_ ] ( expression.md ) which results in a
19+ reference to declared variable.
20+
21+ The type and coercion-method of the variable can be set by using the
22+ [ _ coerce_ ] ( coerce.md ) operator on the _ variable_declaration_ or on the
23+ [ _ name_ ] ( name.md ) .
24+
25+ If the type is not explicitly set, the exact type of the first assigned value is
26+ used as the type of the variable. The coercion-method is ` := ` , which means that
27+ any subsequent assignment to the variable must be of exactly the same type.
28+
29+ The assignment operator can be either:
30+ - ` = ` which assigns a value to the newly created variable, or
31+ - ` += ` which assigns a value to a newly created variable or calls the ` += ` operator
32+ an a existing variable of the same name and type.
You can’t perform that action at this time.
0 commit comments