If you declare a variable outside a procedure, you make it recognizable to all the procedures in your script. The lifetime of a variable depends on how long it exists. The lifetime of a script-level variable extends from the time it is declared until the time the script is finished running. At procedure level, a variable exists only as long as you are in the procedure. When the procedure exits, the variable is destroyed.
Local variables are ideal as temporary storage space when a procedure is executing.
You can have local variables of the same name in several different procedures because each is recognized only by the procedure in which it is declared. Variables Much of the time, you only want to assign a single value to a variable you have declared. A variable containing a single value is a scalar variable. Other times, it is convenient to assign more than one related value to a single variable. Then you can create a variable that can contain a series of values.