JavaScript Scope
Scope refers to the availability of variables and functions in certain parts of the code.
Scope refers to the availability of variables and functions in certain parts of the code. In JavaScript, a variable has two types of scope:
Global Scope
Local Scope
Global Scope
A variable declared at the top of a program or outside a function is considered a global scope variable.
The value of a global variable can be changed inside a function. It is a good practice to avoid using global variables because the value of a global variable can be changed in different areas of the program. It can introduce unknown results in the program.
In JavaScript, a variable can also be used without declaring it. If a variable is used without declaring it, that variable automatically becomes a global variable.
Local Scope
A variable can also have a local scope. It can only be accessed within a function. The let keyword is block-scoped (the variable can be accessed only in the immediate block). And var keyword has function scope.
Remember no teacher, no book, no video tutorial, or no blog can teach you everything. As one said Learning is Journey and Journey never ends. Just collect some data from here and there, read it, learn it, practice it, and try to apply it. Don’t feel hesitant that you can’t do that or you don’t know this concept or that concept. Remember every programmer was passed from the path on which you are walking right now. Remember Every Master was Once a Beginner. Work hard and Give your best.
So That's it for JavaScript Scope Guys. Wanna get in touch with me? Follow me up below.
Jai Hind, Vande Mataram 🇮🇳