# Variable scope in IJulia Jupyter notebook

**URL:** https://discourse.julialang.org/t/variable-scope-in-ijulia-jupyter-notebook/38264
**Category:** General Usage
**Tags:** question
**Created:** [April 26, 2020, 9:41pm UTC](https://discourse.julialang.org/t/variable-scope-in-ijulia-jupyter-notebook/38264 "2020-04-26T21:41:59Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Ken\_Lin](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ken_lin/32/14367_2.png) [@Ken\_Lin](https://discourse.julialang.org/u/Ken_Lin)
#### Post date: [April 26, 2020, 9:41pm UTC](https://discourse.julialang.org/t/variable-scope-in-ijulia-jupyter-notebook/38264/1 "2020-04-26T21:41:59Z")

</div>

I’m using Jupyter notebook by doing:

```julia
using IJulia
notebook()

```

Now, if I try the following code:

```julia
a = 1
for i = 1:2
    a = a+1
end

```

and the value of `a` would be 3. Isn’t it supposed to be an error as for loop can not modify the value of the global variable `a`?

Indeed if I run the code in Julia directly, instead of in Jupyter, I will get the error:" **ERROR:** UndefVarError: a not defined".

I don’t understand why the responds are different. Is there anything I am missing with the Jupyter notebook?

Thank you!

---

<div class="post-metadata">

### Author: ![Mason](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mason/32/2423_2.png) [@Mason](https://discourse.julialang.org/u/Mason)
#### Post date: [April 26, 2020, 9:49pm UTC](https://discourse.julialang.org/t/variable-scope-in-ijulia-jupyter-notebook/38264/2 "2020-04-26T21:49:48Z")

</div>

IJulia.jl uses a plugin called [SoftGlobalScope.jl](https://github.com/stevengj/SoftGlobalScope.jl) to provide this behaviour. However, Julia’s REPL will start providing this behaviour as well [starting in Julia 1.5](https://github.com/JuliaLang/julia/pull/33864). Note, this will not apply to scripts or packages, only the REPL.

---

<div class="post-metadata">

### Author: ![Ken\_Lin](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ken_lin/32/14367_2.png) [@Ken\_Lin](https://discourse.julialang.org/u/Ken_Lin)
#### Post date: [April 27, 2020, 12:57am UTC](https://discourse.julialang.org/t/variable-scope-in-ijulia-jupyter-notebook/38264/3 "2020-04-27T00:57:26Z")

</div>

Thank you! Do IJulia and Julia have other different behaviors that might cause confusions? Or is there a way to detect such differences?

Since IJulia doesn’t give an error in my example, I can’t realize my code is wrong until I run it in Julia.

I always develop my codes in IJulia, if there are such different behaviors I don’t realize, I might be writing codes that will not work in Julia.
