# Difference between global and const

**URL:** <https://discourse.julialang.org/t/difference-between-global-and-const/21075>\
**Category:** New to Julia\
**Created:** [February 22, 2019, 12:50pm UTC](https://discourse.julialang.org/t/difference-between-global-and-const/21075 "2019-02-22T12:50:24Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![HelgavonLichtenstein](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/helgavonlichtenstein/32/5005_2.png) [@HelgavonLichtenstein](https://discourse.julialang.org/u/HelgavonLichtenstein)\
**Post date:** [February 22, 2019, 12:50pm UTC](https://discourse.julialang.org/t/difference-between-global-and-const/21075/1 "2019-02-22T12:50:24Z")

</div>

At the moment I do not understand the difference between `global` and `const` used at the global scale. I understand that there can be `global` variables that change while `const` variables do not, and that I should [not use global variables](https://docs.julialang.org/en/v1/manual/performance-tips/index.html), but then `const` is defined as `used to declare global variables whose values will not change. In almost all code (and particularly performance sensitive code) global variables should be declared constant in this way.`

Does this mean I should try to avoid all `const` in the global scope? Would that not make more work for Julia if I am reusing the same constants within different functions?

---

<div class="post-metadata">

**Author:** ![rdeits](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rdeits/32/286_2.png) [@rdeits](https://discourse.julialang.org/u/rdeits)\
**Post date:** [February 22, 2019, 1:00pm UTC](https://discourse.julialang.org/t/difference-between-global-and-const/21075/2 "2019-02-22T13:00:56Z")

</div>

> [@HelgavonLichtenstein](#):
>
> Does this mean I should try to avoid all `const` in the global scope?

No, just the opposite. If you have a global variable, you can and should mark it as `const`.

If a global variable is not const, then its type could change at any time, and therefore the compiler cannot generate efficient specialized code when you use that variable.

---

<div class="post-metadata">

**Author:** ![HelgavonLichtenstein](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/helgavonlichtenstein/32/5005_2.png) [@HelgavonLichtenstein](https://discourse.julialang.org/u/HelgavonLichtenstein)\
**Post date:** [February 22, 2019, 1:02pm UTC](https://discourse.julialang.org/t/difference-between-global-and-const/21075/3 "2019-02-22T13:02:57Z")

</div>

Thank you for the clarification!
