# Context is reset to default when input is 0

**URL:** https://discourse.nodered.org/t/context-is-reset-to-default-when-input-is-0/24914
**Category:** General
**Created:** [15 April 2020 22:09 UTC](https://discourse.nodered.org/t/context-is-reset-to-default-when-input-is-0/24914 "2020-04-15T22:09:06Z")
**Posts on this page:** 1
**Showing post:** 2

<div class="post-metadata">

### Author: ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)
#### Post date: [15 April 2020 22:35 UTC](https://discourse.nodered.org/t/context-is-reset-to-default-when-input-is-0/24914/2 "2020-04-15T22:35:27Z")

</div>

because of this line

```auto
context.dim = context.dim || 100.0;

```

When you set `context.dim` to `0`, the next time it runs, it gets the 100.0

THE REASON IS... `0 == false`

Do this instead...

```auto
if(context.dim == "undefined"){
  context.dim = 100.0 //init value ONLY if its undefined
}

```

NOTE: accessing context in this manner is depreciated (see the node red documentation on context.get, context.set)

---

_[View the full topic](https://discourse.nodered.org/t/context-is-reset-to-default-when-input-is-0/24914)._
