Local Scope: Variables that 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 are 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 a value to a variable inside a function without declaring it using the “var” keyword.
Example: In this example, we will define global variables with user input and manipulate them from inside the function
Please Login to comment...