Declaration
When simply declaring a name, the type must be explicitly stated
let a: int;
However if a name is being assigned on declaration the type can be inferred, and thus ommited from the code
let a = 1;
Both of these statements define a
as an int
, however only the second one defines the value.
Attempting to use an undefined value will result in a crash at compile time.
Info
This example will not compile, as line 3 attempts to use an undefined value.
1 2 3 |
|
- The value refered to by
a
has been consumed
Last update:
November 13, 2022