Go language provides a special feature known as an anonymous function. An anonymous function is a function which doesn’t contain any name. It is useful when you want to create an inline function. In Go language, an anonymous function can form a closure. An anonymous function is also known as function literal.
Syntax:
func(parameter_list)(return_type){
// code..
// Use return statement if return_type are given
// if return_type is not given, then do not
// use return statement
return
}()
Example:
package main
import "fmt"
func main() {
func(){
fmt.Println( "Welcome! to GeeksforGeeks" )
}()
}
|
Output:
Welcome! to GeeksforGeeks
Important Points:
Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape,
GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out -
check it out now!
Last Updated :
22 May, 2020
Like Article
Save Article