# Let's make the variable non-rebindable

**URL:** <https://forum.elixirforum.com/t/lets-make-the-variable-non-rebindable/29444>\
**Category:** Discussions\
**Tags:** elixr\
**Created:** [February 27, 2020, 4:47am UTC](https://forum.elixirforum.com/t/lets-make-the-variable-non-rebindable/29444 "2020-02-27T04:47:05Z")\
**Posts on this page:** 1\
**Showing post:** 3

<div class="post-metadata">

**Author:** ![sasajuric](https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/sasajuric/32/991_2.png) [@sasajuric](https://forum.elixirforum.com/u/sasajuric)\
**Post date:** [February 27, 2020, 7:01am UTC](https://forum.elixirforum.com/t/lets-make-the-variable-non-rebindable/29444/3 "2020-02-27T07:01:23Z")

</div>

> [@pillaiindu](#):
>
> they think if the variable is rebindable, may be the data isn’t immutable

Let’s try to unpick this argument.

First, let’s see a javascript example of mutability:

```javascript
a = {}

// b holds a reference to the same data as a
b = a

// mutability: we're changing the data
a.x = 1

// data pointed to by b is implicitly changed
console.log(b) // {x: 1}

```

Now let’s see a javascript example of rebinding:

```javascript
a = {}
b = a

// rebinding: a points to different data
a = {x: 1}

// rebinding a didn't change anything in b, hence it's not mutability
console.log(b) // {}

```

The former (mutability) is problematic because it’s much harder to reason about the code. For example if we invoke `foo(a)`, we have no way of knowing if this will change something in `a`. We need to read the code of `foo` and all the code it invokes (recursively!) to reliably answer that. This is extremely tedious, prone to errors, and whatever assumptions we have about the code today can implicitly change tomorrow without us knowing it, for example if a team member changes some indirect dependency of `foo`.

The latter (variable rebinding) doesn’t suffer from such problems, because rebinding doesn’t change the data.

---

_[View the full topic](https://forum.elixirforum.com/t/lets-make-the-variable-non-rebindable/29444)._
