Local Scope: Variables which are declared inside a function is called local variables and these are accessed only inside the function. Local variables are deleted when the function is completed.
Global Scope: Global variables can be accessed from inside and outside the function. They are deleted when the browser window is closed but is available to other pages loaded on the same window. There are two ways to declare a variable globally:
- Declare a variable outside the functions.
- Assign value to a variable inside a function without declaring it using “var” keyword.
- Before clicking the button:
- After clicking add button:
- After clicking subtract button: