GOLANG

The anatomy of Functions in Go

Like JavaScript, functions in Go are first-class citizens. They can be assigned to variables, passed as an argument, immediately invoked or deferred for last execution.

Uday Hiwarale
RunGo
Published in
10 min readAug 18, 2018

--

(source: pexels.com)

☛ What is a function

A function, in general, is a small piece of code that is dedicated to a perform particular task based on some input values. We create a function so that we can perform such an operation whenever we want from wherever we want by providing some input values.

These input values provide extra information to a function and they are totally optional. A function’s execution may or may not return any result.

In Go, a function is defined using func keyword.

func dosomething() {
fmt.Println("Hello World!")
}

This function can be called from anywhere inside a function body in the program. For example, we have a dosomething function that prints some characters to the standard output.

https://play.golang.org/p/THBF9b1nOr-

☛ function name convention

--

--