03 Type inference
var lets the initializer determine a local variable's static type.
norm
main() {
var count = 2
var title = "New tasks"
printLine(title)
printLine(count)
count = count + 1
printLine(count)
}Output:
text
New tasks
2
3count is inferred as Integer and title as String. Reassignment still checks the original type; var does not make a variable dynamically typed. An initializer such as null or [] needs a type supplied by context, so it cannot stand alone after var.
Try it: Try changing count = count + 1 to a string assignment and inspect the diagnostic.
Precise rules: Language Reference.