July 2018
Beginner
202 pages
5h 42m
English
You can give a variable local to a chunk the same name as a global variable. If you were to do this, then print the variable inside the chunk, what would happen? The value of the variable inside the chunk would print.
This is called variable shadowing. If the same variable name is used in different scopes, the variable closest to the scope you are using it in will be used. The following code example demonstrates this concept:
message = "global-scope"-- This should print: global-scopeprint ("message: " .. message)do -- Shadow the message variable local message = "local-scope" -- This print uses the variable declared -- in this block (shadowing). Should print: local-scope print ("message: " .. message)end
-- The variable that was ...