Chapter 07 — Functions
Level: beginner Estimated time: 6 h Prerequisites: chapter 06 — Collections:
List,Set, andMapWhat you will be able to do by the end: break a program into clear functions with parameters, return values, optional and named parameters, and write a small combat engine built entirely from functions.
07.0 — Chapter objectives
By the end of this chapter, you will be able to:
- understand why a function prevents code repetition;
- declare a function;
- call a function;
- understand the
voidkeyword; - return a value with
return; - choose a return type;
- define parameters;
- pass arguments;
- use multiple parameters;
- distinguish positional parameters from named parameters;
- use optional
[ ]parameters; - use named
{ }parameters; - use
required; - provide default values;
- write arrow functions
=>; - write anonymous functions;
- understand variable scope;
- distinguish local variables from global variables;
- pass a function as a parameter to another function;
- write a simple recursive function;
- break a large program into small functions.
Comments
Comments are powered by GitHub Discussions
Sign in with GitHub to join the discussion