function
can access all variables defined inside the function, like this:function
can also access variables defined outside the function, like this:var
, let
, or const
) are always global, even if they are created inside a function.function
to increase the counter:add()
function, to prevent other code from changing it:plus()
has access to the counter
variable in the parent function:plus()
function from the outside.counter = 0
only once.add
is assigned the return value of a self-invoking function.