Variables
Variables are declared with the let
keyword. The type of most variables can be inferred automatically, but you can also add an explicit type annotation if needed.
By default, Wing doesn't let you reassign to variables, unless you add the var
modifier. See this blog post for more details.
main.w
// var delcares a varaible. Wing infers the type
let a = "initial";
log(a);
// type can also be declared
let b: num = 1;
let c: num = 2;
log("{b}, {c}");
// variables cannot be changed using let without var
let d: str = "Hello";
// d = "Test"; // error: Variable is not reassignable
// makes variable reassignable
let var s = "hello";
s = "hello world"; // compiles
log(s);
Wing console output
# Run locally with wing console
wing it
initial
1, 2
hello world