Skip to content
masterclass Buddy

Go · Concept

defer

defer delays a function or method call until its surrounding function is about to return. Calls run in reverse order, and deferred functions can change named return values or recover a panic.

Last updated

Syntax

defer Expression

In-depth API docs are only for subscribers: parameters, examples, common mistakes and interview practice.

Subscribe
  • panic
  • recover
  • return
  • named result parameters
  • goroutine

Source: The Go Programming Language Specification. Checked 2026-11-03.