To declare a variable, use the term
var and then the variable name, and then set the variable to its initial value (what you want the variable to start off holding).
This line of script declares a variable, and sets it to hold an empty string:
var pickYerPoison = "";
This line of script declares a variable, and sets it to hold a number:
var luckyNum = 30;
This line of script declares a variable, and sets it to hold what the script gets back from the prompt:
var users_day = prompt("How is your day going?");
users_dayis the variable, and it will hold whatever the user types in as a result of the
You only need to declare the variable the first time it is used. Other lines containing the variable only need to refer to it by name.
A Local variable is a JS variable declared and used inside the same function
Local variables in JS remember information inside the function they have been declared in. After the function finishes executing its current run, the variable is forgotten.
If different functions all use local variables with the same name, the variables don't generally conflict because they are local, and only active while each function is running. Local variables in a function only remember their information as long as it takes for that function to execute completely, and then they are gone, which sometimes allows limited reuse of local variable names between functions.
A Global variable is a JS variable declared inside script tags (not declared inside a function), and then used in script tags and possibly in a function (or in several functions)
Global variables in JS remember information inside AND outside functions, and from function to function.
This means that the information in a global variable can be accessed and used in multiple functions, and/or outside of functions in script tags!
If different functions all use global variables with the same name, the variables are really all the same variable, sharing information between functions.
JS Cookies are not technically variables, but are a memory technology as variables are.