🔨 Scopes and Closures

  • Explanation::

    • A scope, is the context that a function or a variable are inside of javascript, so, if for example you set a new function, and inside of it declare a variable, this variable will be inside of this function scope, other function in the same file will not be able to access it, because each function has itself scope.

    • We have the global scope and local scope, the variable inside the function is in a local scope, a global scope mans that the variable can be acces by any part of the file, or program.

    • Closure is a function that returns a function, so, we can for example, return a closure inside of a function.

    • A closure is a combination of a function and the lexical environment within which that function was declared. It allows a function to maintain access to the variables from its outer (enclosing) scope even after the outer scope has finished executing.