And one thing you will need is Patience.
Before going into the major focus of this article, the aim is for you to be able to understand the following, which is outlined in the table of Content, which will be in bits. It will be great, if you follow through this series
Table of Content
i) Local Scope
ii) Global Scope
2) Primitive Data Types
5) Expressions and Statements
What is Scope
Scope is determining where Variables, functions and objects are accessible during run time in our code. This means the scope of a variable, where it can be accessed is controlled by the location of where the variable was declared.
Scope is a very important concept in programming. Whenever you assign a variable to a value, you want to always access that value at any point in time in your code. That’s what Scope does. It’s answers the question “accessibility of Values “
I) Global Scope
2) Local Scope
Local Scope is often regarded as Function Scope. A local scope, i often describe it as “its own scope”. Given that any variable declared within that function is only accessible from that function and any nested functions. It cannot be accessible outside of that function.
Local Scope often gain more priority than the Global Scope.
If you declare a local variable and a global variable with the same name, the local variable will take precedence when you use it inside a function. This type of behavior is called shadowing. Simply put, the local variable shadows the universal variable.
Hope you have been able to understand the both concepts.😊
Block Scope is often used with expression and decision statements. Like the If statements and Loops. Block Scope is basically anything that is wrapped in curly braces.
It’s important to note that let and const have a block level scope, while var has a function scope.
I will describe the block scope as a proctective scope.Its helps avoid ressigning of values, especially when the same var is declared, using the let in a block scope, will help for a more organised code.
That’s is all for now!😀
I hope this was helpful, as a guide to understanding the fundamentals of JS.
The next series will be talking about Primitive Data types and Operators.