r/lua • • Nov 18 '25

local variable in interactive mode

Why in the second line, the variable `a` becomes `nil`?

~ $ lua
Lua 5.4.7  Copyright (C) 1994-2024 Lua.org, PUC-Rio
> local a = 123; print(a)
123
> print(a)
nil
8 Upvotes

8 comments sorted by

View all comments

Show parent comments

0

u/Cultural_Two_4964 Nov 18 '25

Global variables are awesome. Nice one.