Here are the top Go interview questions to prepare for your next role.
1️⃣ If you import a package in Go but never use it, will the code compile successfully?
- A) No, the compiler reports an unused import error
- B) Yes, as long as the package builds without errors
- C) It depends on the project's module settings
- D) Yes, but only if the file has a main function
2️⃣ How can you explicitly name return values in a Go function signature?
- A) By declaring variables inside main() with the same names
- B) By specifying identifiers before the return types
- C) By prefixing return types with the keyword "ret"
- D) By adding names after the closing brace
3️⃣ How many methods must a type implement to satisfy the empty interface in Go?
- A) 0
- B) At least one exported method
- C) 1
- D) 2
4️⃣ Are function parameters in Go passed by value or by reference by default?
- A) Passed by reference
- B) Passed by reference unless explicitly copied
- C) Passed by pointer only when using structs
- D) Passed by value
5️⃣ What occurs in Go when you attempt to unmarshal JSON data into a struct that contains unexported fields?
- A) The unexported fields are forcefully updated
- B) The decoding operation panics
- C) The JSON decoder skips the struct entirely
- D) The unexported fields remain unchanged