Creating a function

To create a basic function:

Then you call it with:

This would print a message “Just created my first function!” in the console.

To create a function with parameters:

This function will take 2 parameters – ‘a’ and ‘b’ and then return the Sum of both as an Integer value.

The way we call the function is:

By default in functions you are not required to list the first parameter.
If you want to make any of the parameters required you have to put “#” in front of it and
if you want to make it an optional you put “_ ” in front.
So a function with both parameters required will be:

And a function with both parameters optional will look something like: