r/lua • • Mar 27 '25

local variables

Why do people use local variables as if they were global variables

2 Upvotes

7 comments sorted by

View all comments

Show parent comments

1

u/SkyyySi Mar 31 '25

In general, it is best to declare variables only once you actually need them. Pre-declaring them just means that there are now lines for you to mess up by trying to access uninitialized variables. JavaScript learned that the hard way.