Local variables are declared within a function and they have local scope. Local scope means these variable can only accessed within the function.
Local variable example
Local variables are created when the a function starts and deleted when the function is completed.
All variable declared outside of a function is considered global variables and they have global scope. global scope means these variable can be accessed by all the scripts and functions on the page.
Global variable example