Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Defer and parameters

package main

import "fmt"

func main() {
	text := "start"
	defer fmt.Println(text)
	defer say(text)
	text = "end"
	fmt.Printf("end: %v\n", text)
}

func say(text string) {
	fmt.Println(text)
}
  • The deffered function will see the its parameter when we defer the function not when it is executed