Basic function usage:
https://codeeval.dev/gist/0309cb6b537361d2aaf4eed3220e2825
A function can optionally declare a set of parameters:
https://codeeval.dev/gist/26a4febfe8f8d87c01cd1c7bc9e86836
Type for firstName
is omitted because it is identical to lastName
.
A function can return one or more values to the caller:
https://codeeval.dev/gist/dd5d25485e5cccff6d1c8c10145a283c
You can name returned values in which case they act as implicit local variable.
An empty return
statement can then be used to return their current values. This is known as “naked” return.
https://codeeval.dev/gist/70d1523c8b4c5bc79efc68e9f98b22c3
Two important things must be noted:
return
statement must always be providedUsing named return values is considered a bad practice that hinders readability, especially in longer function. Explicit is better than implicit.
A variadic function can be called with any number of trailing arguments. Those elements are stored in a slice.