Dynamic scope

Dynamic scope resembles lexical scope in its visibility rules. Still, instead of looking outward in compile-time scopes, lookup traverses backward through all of the function calls we’ve made to reach the current code. Dynamic scope applies only to global and package global variables (since lexicals aren’t visible outside their scopes). While a global package variable may be visible within all scopes, its value may change depending on localization and assignment:

Get hands-on with 1200+ tech skills courses.