Scope of a Variable:
Scope is defined as the visibility of a variable. If you don't know how to write JavaScript functions then understanding scope may be difficult for you. Leave it if you feel your head spinning.
Programming languages usually allow two broad types of variables: local and global. A local variable is one that can be used in a single function. If you try to change / read the value of a local variable from outside that function, an error will be reported. A global variable, as the name suggests, can be read / changed from any function on a single page.
You don't need to do anything special to incorporate scope of a variable - its automatically handled for you. A variable that is defined in a function (we will see how to define a variable shortly) is local. A variable defined outside any function is global. These logical concepts are simply for making you a better programmer.
Using Variables:
A variable is defined as var variableName;. The part var and the semicolon are part of the syntax and will always be used like this. variableName is the name of the variable that you want to define.
Values are assigned as variableName = value. For example to mean "let i be equal to 10", we write i=10;. Some examples are given below: