Hi Philipp,
Global variables are used to share a single value among various functions.
There are many other ways to do. You can refer to
The most secure way to extend the scope of a function variable is to use function input and output arguments, which allow you to pass values of variables.
Thanks,
Anmol Dhiman