This declares a nested function, or a function inside another function. logMessageInner can only be used in the function logMessageOuter and not outside of it. The function is scoped the same way as a variable declared inside logMessageOuter.
Summary
Scope is an important aspect of variable declarations, function declarations and function parameters, which defines where they can be used. In short, each pair of braces {
and }
defines a new scope, and anything not inside any braces is at the top level. Something declared in a particular scope can be used anywhere inside that scope, including inner scopes, but not outside of that scope. Scope becomes an important feature when dealing with functions, which is why we took a little detour to cover it now.
These rules about scope help keep code organized as it prevents things being accidentally used outside of where they're meant to be used. It also generally removes the need to worry about if a name is used somewhere else in a large program, since you only need to think about what is in scope for a particular piece of code.
It is possible to use top-level functions and variables in other script files if they are explicitly placed in global scope, or exported and imported, but these are more advanced topics that we'll cover later on in this guide.