So, what is scope? In programming, scope refers to the visibility and accessibility of variables, functions and objects during runtime. Put simply, scope says whether you can use particular variable, functions or object in your code at a specific location or not. And the runtime? Runtime is a time during which a computer program is executing.
One more thing about scope. You can also create scope inside a scope, or let’s say “child” scopes. These are called lexical scopes. In this case, these lexical scopes can access variables, functions or objects defined in a parent scope. However, parent scope can’t access variables, functions or objects defined in a its lexical scopes.
Don’t worry if this sounds too difficult now. We will talk more about all this, and more, later in this tutorial. There will also be examples that will help you understand all these concepts. But before that, let’s first talk about some benefits of scope.