Pratik Mota

Software Developer

Technical Writer

Creative

Startup Enthusiast

Pratik Mota

Software Developer

Technical Writer

Creative

Startup Enthusiast

Blog Post

What is differ in Golang ?

December 12, 2021 GOLANG
What is differ in Golang ?

A defer statement defers the execution of a function until the surrounding function returns.

The deferred call’s arguments are evaluated immediately, but the function call is not executed until the surrounding function returns.

package main

import "fmt"

func main() {
	defer fmt.Println("First Statement")
	fmt.Println("Second Statement")
}

OUTPUT:

Second Statement

First Statement

We can create a deferred method, or function, or anonymous function by using the defer keyword.

In Golang, multiple defer statements are allowed in the same program and they are executed in LIFO(Last-In, First-Out) order.

Taggs:
Write a comment