# I think I'm doing mutable wrong

**URL:** <https://talk.observablehq.com/t/i-think-im-doing-mutable-wrong/5648>\
**Category:** Help\
**Created:** [October 2, 2021, 6:08am UTC](https://talk.observablehq.com/t/i-think-im-doing-mutable-wrong/5648 "2021-10-02T06:08:51Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![hellonearthis](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/hellonearthis/32/3935_2.png) [@hellonearthis](https://talk.observablehq.com/u/hellonearthis)\
**Post date:** [October 2, 2021, 6:08am UTC](https://talk.observablehq.com/t/i-think-im-doing-mutable-wrong/5648/1 "2021-10-02T06:08:51Z")

</div>

On a mousepress the code checks of the `audioContext` is defined (not null) and defines the `audioContext`  
But it seems to be doing the inverse of the `if condition`

Is this because of something with mutable that I don’t fully get as Matt’s code works fine on glitch.

```auto
    if (!audioContext) {
      const AudioContext = window.AudioContext || window.webkitAudioContext;
      mutable audioContext = new AudioContext();  

```

> **[Frontend masters Web-Audio by Matt DesLauriers](https://observablehq.com/d/8c384ab4e35b5d5b#cell-15)**
>
> 05 Waveform Advanced (glitch.com) https://github.com/mattdesl/workshop-web-audio Replay only available as editing still happening

---

<div class="post-metadata">

**Author:** ![tomlarkworthy](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/tomlarkworthy/32/5940_2.png) [@tomlarkworthy](https://talk.observablehq.com/u/tomlarkworthy)\
**Post date:** [October 2, 2021, 6:41am UTC](https://talk.observablehq.com/t/i-think-im-doing-mutable-wrong/5648/2 "2021-10-02T06:41:13Z")

</div>

You need to use the mutable keyword at read time as well, otherwise the changing in the value causes the cell to reevaluate because of the read dependency.

```auto
if (!mutable audioContext) {
      const AudioContext = window.AudioContext || window.webkitAudioContext;
      mutable audioContext = new AudioContext(); 

```

Every use of audioContext needs prefixing with mutable (there are lots of uses lower down in the cell too)

I think this is nearly it [Comparing Frontend masters Web-Audio by Matt DesLauriers to Frontend masters Web-Audio by Matt DesLauriers / Observable](https://observablehq.com/compare/8c384ab4e35b5d5b...b931242e272015a6)

---

<div class="post-metadata">

**Author:** ![hellonearthis](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/hellonearthis/32/3935_2.png) [@hellonearthis](https://talk.observablehq.com/u/hellonearthis)\
**Post date:** [October 2, 2021, 7:23am UTC](https://talk.observablehq.com/t/i-think-im-doing-mutable-wrong/5648/3 "2021-10-02T07:23:52Z")

</div>

Thanks, I get it now, I needed to add `mutable` to all the mutable values used.
