← Back to archive

Stdle #65 · defer · 2026-08-10

What does this Go snippet output?

A past puzzle — fully playable. 4 attempts, hints on wrong guesses.

package main
import "fmt"
func f() (n int) {
defer func() {
if recover() != nil {
n = 7
}
}()
n = 3
panic("x")
}
func main() {
fmt.Println(f())
}
Defer
4 attempts left

Answer & explanation