# Declaring a variable whose value cannot be changed

**URL:** https://discourse.julialang.org/t/declaring-a-variable-whose-value-cannot-be-changed/44372
**Category:** General Usage
**Tags:** question
**Created:** [August 5, 2020, 10:04pm UTC](https://discourse.julialang.org/t/declaring-a-variable-whose-value-cannot-be-changed/44372 "2020-08-05T22:04:47Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Haolun\_Li](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/haolun_li/32/13897_2.png) [@Haolun\_Li](https://discourse.julialang.org/u/Haolun_Li)
#### Post date: [August 5, 2020, 10:04pm UTC](https://discourse.julialang.org/t/declaring-a-variable-whose-value-cannot-be-changed/44372/1 "2020-08-05T22:04:47Z")

</div>

`const x=1` then variable `x`’s value can be changed if a variable of the same type is reassigned. Is it possible to declare a variable so its value will NOT be changed by any assignment?

---

<div class="post-metadata">

### Author: ![nilshg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nilshg/32/2283_2.png) [@nilshg](https://discourse.julialang.org/u/nilshg)
#### Post date: [August 6, 2020, 7:19am UTC](https://discourse.julialang.org/t/declaring-a-variable-whose-value-cannot-be-changed/44372/2 "2020-08-06T07:19:16Z")

</div>

Related: [Does declaring a variable to be constant do anything at all? - #11 by yuyichao](https://discourse.julialang.org/t/does-declaring-a-variable-to-be-constant-do-anything-at-all/6029/11)

---

<div class="post-metadata">

### Author: ![yuyichao](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yuyichao/32/20_2.png) [@yuyichao](https://discourse.julialang.org/u/yuyichao)
#### Post date: [August 6, 2020, 1:31pm UTC](https://discourse.julialang.org/t/declaring-a-variable-whose-value-cannot-be-changed/44372/3 "2020-08-06T13:31:45Z")

</div>

That thread does not seem to answer this question. `const` is the way to declare a variable to not be assignable again. Assignment of same type is allowed only for debugging convience since it has a lower risk of crashing. Nevertheless, doing that is basically undefined behavior and you should not ignore warning raised when you do that.
