Recall & Review
beginner
What is short variable declaration in Go?
It is a way to declare and initialize a variable in one step using := instead of var and =.
Click to reveal answer
beginner
How do you declare a variable named
count with value 10 using short variable declaration?You write
count := 10. This creates and sets count to 10.Click to reveal answer
intermediate
Can you use short variable declaration outside functions in Go?
No, short variable declaration (:=) can only be used inside functions, not at package level.
Click to reveal answer
intermediate
What happens if you use := with a variable name that already exists in the same scope?
If at least one new variable is declared, it reuses existing variables and declares new ones. If none are new, it causes a compile error.
Click to reveal answer
beginner
Why is short variable declaration useful?
It makes code shorter and easier to read by combining declaration and initialization in one step.
Click to reveal answer
Which symbol is used for short variable declaration in Go?
✗ Incorrect
The := symbol declares and initializes a variable in one step inside functions.
Where can you use short variable declaration in Go?
✗ Incorrect
Short variable declaration is allowed only inside functions, not at package level.
What happens if you write
x := 5 when x already exists in the same scope?✗ Incorrect
If no new variables are declared with :=, Go throws a compile error.
Which of these is a correct short variable declaration?
✗ Incorrect
The correct syntax is
a := 10 without the var keyword.Why might you prefer short variable declaration over var with = ?
✗ Incorrect
Short variable declaration is concise and combines declaration and initialization.
Explain how short variable declaration works in Go and when you can use it.
Think about where you write := and what it does.
You got /4 concepts.
Describe what happens if you try to use := with only existing variables in the same scope.
Consider Go's rules for redeclaring variables with :=
You got /3 concepts.