Go · Stage 6 – Reusable Code · Lesson 37 of 64

Parameters and Return Values

Define a function that receives a value and returns a result.

Go code

func double(number int) int {
    return number * 2
}

fmt.Println(double(4))
Line-by-line explanation
  1. Func begins the definition.
  2. Number is an int parameter.
  3. The second int is the return type.
  4. Return sends the calculation back.
  5. The call passes 4.
Expected output
8

This is the expected result.