I'm new to Lua. I noticed the following pattern in Lua. But I'm not understanding why it's happening.
Here, a is a global variable and it's accessible inside the foo function:
function foo()
print(a)
end
a = 10
foo() -- 10
But if we declare a as local it's not any more accessible inside the function foo:
function foo()
print(a)
end
local a = 10
foo() -- nil
Why the global variable is accessible inside the function while the local is not?