Skip to content

Commit e3d0ba1

Browse files
tomtuamnuqN5N3
authored andcommitted
Add description of local kw in global scope (JuliaLang#42794)
1 parent 48b386a commit e3d0ba1

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

doc/src/manual/variables-and-scoping.md

+16
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,22 @@ julia> module E
9999
ERROR: cannot assign variables in other modules
100100
```
101101

102+
If a top-level expression contains a variable declaration with keyword `local`,
103+
then that variable is not accessible outside that expression.
104+
The variable inside the expression does not affect global variables of the same name.
105+
An example is to declare `local x` in a `begin` or `if` block at the top-level:
106+
107+
```jldoctest
108+
julia> x = 1
109+
begin
110+
local x = 0
111+
@show x
112+
end
113+
@show x;
114+
x = 0
115+
x = 1
116+
```
117+
102118
Note that the interactive prompt (aka REPL) is in the global scope of the module `Main`.
103119

104120
## Local Scope

0 commit comments

Comments
 (0)