I believe the first var1 is classed as global across all addons and is the same as adding it to the _G table.
I am not sure if ESO has the equivalent of the addon wide data table but that would be the only way to be addon wide across all files for just a single addon.
Lua Code:
globalVar = "All Addons can see me"
local localVar = "This file can see me"
function globalFunc = All addons can use me
global globalFunc = function() ... same as above
local function localFunc = Only this file can use me
local localFunc = function() .. same as above
Lua Code:
local function aFunc()
local localVar = "Only this function has access to me"
return localVar ... unless I return it so that they can use it
end
Lua Code:
for I = 1,10 do
local localVar1 = "available to the whole for loop"
if I == 4 then
local localVar2 = "available only to the if block"
end
end
Hope these and the other comments help you understand how scope works.