# Significance of global keyword

**URL:** <https://discourse.julialang.org/t/significance-of-global-keyword/49884>\
**Category:** General Usage\
**Created:** [November 10, 2020, 6:00am UTC](https://discourse.julialang.org/t/significance-of-global-keyword/49884 "2020-11-10T06:00:52Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Debraj\_Bhal](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/debraj_bhal/32/19299_2.png) [@Debraj\_Bhal](https://discourse.julialang.org/u/Debraj_Bhal)\
**Post date:** [November 10, 2020, 6:00am UTC](https://discourse.julialang.org/t/significance-of-global-keyword/49884/1 "2020-11-10T06:00:52Z")

</div>

Can someone make me understand the actual significance of global keyword in Julia?

---

<div class="post-metadata">

**Author:** ![mauro3](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mauro3/32/292_2.png) [@mauro3](https://discourse.julialang.org/u/mauro3)\
**Post date:** [November 10, 2020, 7:15am UTC](https://discourse.julialang.org/t/significance-of-global-keyword/49884/2 "2020-11-10T07:15:31Z")

</div>

Presumably you’ve read the manual: [Scope of Variables · The Julia Language](https://docs.julialang.org/en/v1/manual/variables-and-scoping/)?

If so, maybe you can be a bit more specific, what your question is.

---

<div class="post-metadata">

**Author:** ![Debraj\_Bhal](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/debraj_bhal/32/19299_2.png) [@Debraj\_Bhal](https://discourse.julialang.org/u/Debraj_Bhal)\
**Post date:** [November 10, 2020, 1:47pm UTC](https://discourse.julialang.org/t/significance-of-global-keyword/49884/3 "2020-11-10T13:47:05Z")

</div>

Thank you @mauro3, I was confused when we declare a variable outside ,not within any block, what is its scope?

---

<div class="post-metadata">

**Author:** ![mauro3](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mauro3/32/292_2.png) [@mauro3](https://discourse.julialang.org/u/mauro3)\
**Post date:** [November 10, 2020, 1:52pm UTC](https://discourse.julialang.org/t/significance-of-global-keyword/49884/4 "2020-11-10T13:52:57Z")

</div>

Here it says [Scope of Variables · The Julia Language](https://docs.julialang.org/en/v1/manual/variables-and-scoping/#Global-Scope:)  
“Each module introduces a new global scope, separate from the global scope of all other modules—there is no all-encompassing global scope.”

---

<div class="post-metadata">

**Author:** ![Henrique\_Becker](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/henrique_becker/32/15443_2.png) [@Henrique\_Becker](https://discourse.julialang.org/u/Henrique_Becker)\
**Post date:** [November 10, 2020, 1:56pm UTC](https://discourse.julialang.org/t/significance-of-global-keyword/49884/5 "2020-11-10T13:56:52Z")

</div>

It is global scope, it is the only possibility and you do not need to use the keyword `global` there. You use `global` when you want to refer to a global variable inside a block, specially if the block start assigning a value to the global variable (e.g., `function f(...); global x = 1; ...; end`). Without the `global` it is indistinguishable from just creating a local variable of the same name (i.e., `function f(...); x = 1; ...; end`).

Complementing what @mauro3 said, you could ask yourself, _but what if I am in the REPL outside of any module?_, well, then you are inside the implicit `module` called `Main`, and every variable you define in the REPL are global variables of this implicit module.

---

<div class="post-metadata">

**Author:** ![Debraj\_Bhal](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/debraj_bhal/32/19299_2.png) [@Debraj\_Bhal](https://discourse.julialang.org/u/Debraj_Bhal)\
**Post date:** [November 10, 2020, 7:01pm UTC](https://discourse.julialang.org/t/significance-of-global-keyword/49884/6 "2020-11-10T19:01:49Z")

</div>

Thanks @Henrique_Becker and @mauro3 , for clearing my queries. Now I have greater understanding of the topic.
