gobeginner
Go Basics Quiz
Variables, types, functions, control flow, and Go fundamentals.
7 questions
By EZ4Code Team
1. Which keyword declares a variable in Go?
var
let
def
declare
Explanation: Go uses `var` to declare variables, e.g. `var name string = "Alice"`. You can also use short declaration `:=` inside functions: `name := "Alice"`. `let` is JavaScript/Rust, `def` is Python.
2. What does `:=` do in Go?
name := "Alice"Declares and initializes a variable (short declaration)
Is an alias for =
Compares two values
Declares a constant
Explanation: `:=` is the short variable declaration. It declares a new variable and infers its type from the right-hand side. It can only be used inside functions. Outside functions, you must use `var`.
3. How does Go handle unused variables?
They are silently ignored
They cause a compile-time error
They generate a warning
They are removed at runtime
Explanation: Go is strict: unused local variables cause a compile-time error. This forces clean code. Unused imports also cause errors. (Unused function parameters and package-level variables are allowed.)
4. What is the entry point of a Go program?
package main
func main() {
// ...
}The `main` function in package `main`
The `start` function
The `init` function
The first function in the file
Explanation: A Go executable must have a `package main` declaration and a `func main()` — that's the entry point. `init()` functions run before `main()` but are not the entry point. There's no `start` function.
5. How do you export (make public) an identifier in Go?
Use the `public` keyword
Start the name with an uppercase letter
Use the `export` keyword
Add a `//export` comment
Explanation: Go uses naming convention, not keywords. Identifiers starting with an uppercase letter (e.g. `Println`, `Server`) are exported (public). Lowercase identifiers (e.g. `fmt.println`) are package-private.
6. What does Go return instead of exceptions for errors?
result, err := doSomething()
if err != nil {
return err
}Exceptions
Multiple return values, with error as the last
null pointers
Panic only
Explanation: Go uses explicit error values — functions return `(result, error)` and the caller checks `if err != nil`. This is more verbose than exceptions but makes error handling explicit. `panic` is for unrecoverable errors only.
7. Which type is used for dynamic-length arrays in Go?
slice
array
list
vector
Explanation: Slices (`[]int`) are dynamic-length views over arrays. Arrays (`[5]int`) have fixed length set at compile time. In practice, you almost always use slices. There's no `list` or `vector` builtin (though `container/list` exists for doubly-linked lists).