# Assignment and mutation

**URL:** <https://discourse.julialang.org/t/assignment-and-mutation/19119>\
**Category:** New to Julia\
**Tags:** question\
**Created:** [December 30, 2018, 4:12pm UTC](https://discourse.julialang.org/t/assignment-and-mutation/19119 "2018-12-30T16:12:10Z")\
**Posts on this page:** 1\
**Showing post:** 4

<div class="post-metadata">

**Author:** ![StefanKarpinski](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stefankarpinski/32/24_2.png) [@StefanKarpinski](https://discourse.julialang.org/u/StefanKarpinski)\
**Post date:** [December 30, 2018, 5:03pm UTC](https://discourse.julialang.org/t/assignment-and-mutation/19119/4 "2018-12-30T17:03:15Z")

</div>

The simplest version of this I can come up with is this:

- Assignment changes which object a name refers to: `x = ex` causes the name `x` to refer to the value resulting from the evaluation of the expression `ex`. Assignment _never_ changes the values of any objects.

- Mutation changes the value of an object: `x[i] = ex` and `x.f = ex` both mutate the object referred to by `x` changing a value at index or a property with a name, respectively. Mutation _never_ changes what objects any names in any scope refer to.

Perhaps the confusion comes from the fact that these all use the `=` in their syntax? They’re really totally unrelated. It’s also possible that people think of assignment as setting a named property on some implicit “scope object”. That’s probably a view that can be worked out coherently, in which case having a clear notion of what all the different “scope objects” are would be crucial but I’m not entirely sure if that’s a helpful way to think about the matter or not.

---

_[View the full topic](https://discourse.julialang.org/t/assignment-and-mutation/19119)._
