Curriculum Foundations Variables and declarations
Variables and declarations
TypeScript uses let and const to introduce variables; the type is inferred or annotated explicitly. Go has two short forms for the same job:
name := value— the short declaration. Inferred type. Idiomatic at function scope. This is what you'll write most of the time.var name type = value— the full form. Required at package scope and useful when you want to declare without initialising, or pin the type explicitly.
const exists in Go too, but only for compile-time constants (integers, strings, floats, booleans) — not for "this binding doesn't get reassigned" the way TS uses const. We'll come back to that.
10 ready
01
pick oneInside a function, which is the idiomatic Go translation of this
02
pick oneSometimes you want to spell out a variable's type even when you're
03
pick one TS const means "this binding can't be reassigned." Go const means
04
pick oneTypeScript can declare several variables in one statement by
05
fill blanksFill in the blanks to produce the idiomatic Go translation of the
06
fill blanksFill in the blanks to produce the idiomatic Go form when you want
07
type one lineThe TS program on the left declares two variables and prints
08
type one lineExercise 4 introduced the multi-declaration shape as a multiple
09
write a program Write a Go program that declares three int variables — a := 3,
10
write a programWrite a Go program that demonstrates all three variable-declaration