Go Functions (Part 2) — Saving functions in variables

Photo by Amelie & Niklas Ohlrogge on Unsplash

Variables are not just used for storing integers, strings, boolean…etc, they can also store functions. These variables can then be used to call that function and feed arguments to it.

This article is part of the Functions in Go series.

Here’s an example where we stored a function called add2NumbersTogether inside a variable called add: