It's just nice to know that, if needed, a JavaScript variable can accommodate so much text. Variables defined outside a function are available to any function within the script, as long as all the variables are definined in the script of the same HTML document. These are referred to as global variables. Variables defined inside a function are also global, assuming the var statement is not used when first declaring that variable. These are referred to as local variables.
Global variables remain in memory even after a script has stopped execution.
The variable remains in memory until the document is unloaded. Local variables are treated as if they don't exist outside the function where they are defined. That way, you can use the same variable name inside a function, and that variable won't interfere with the same-named variable elsewhere in the script. Following is an example that demonstrates this. When you click the button, the script displays three alert boxes.