Source file in a function block
To mitigate such issues, the concept of scoping has been ingeniously introduced to encapsulate a library's variables and functionalities within its confines.
Parameters and variables that find their inception within the confines of a function maintain a deliberate confinement, rendering them invisible outside that particular function's scope. This guarded encapsulation fosters a controlled environment where variables, regardless of their points of declaration within the function, are accessible across all portions of the same function. This encapsulation technique effectively seals off the internal workings of a function, thus erecting an impervious barrier that shields it from external interference, a paradigm quite analogous to the concept of namespaces prevalent in statically compiled languages.
Main purposes :
- Avoid clash with other methods/libraries.
- Avoid Global scope, make it local scope.
- Make debugging faster (local scope).
- Avoid overriding already existing variables.
- Use easily referenceable alias for a global variables.