# Strange behaviour of assign of context var with init bool value

**URL:** <https://discourse.nodered.org/t/strange-behaviour-of-assign-of-context-var-with-init-bool-value/9026>\
**Category:** General\
**Created:** [15 March 2019 15:20 UTC](https://discourse.nodered.org/t/strange-behaviour-of-assign-of-context-var-with-init-bool-value/9026 "2019-03-15T15:20:10Z")\
**Posts on this page:** 1\
**Showing post:** 3

<div class="post-metadata">

**Author:** ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)\
**Post date:** [15 March 2019 15:26 UTC](https://discourse.nodered.org/t/strange-behaviour-of-assign-of-context-var-with-init-bool-value/9026/3 "2019-03-15T15:26:59Z")

</div>

> [@Frank2](#):
>
> SetTempCFirstOn = context.get('SetTempCFirstOn') || true

The problem is the way you are trying to set the default value using the || operator.

If you set `SetTempCFirstOn` to `false` then the above code will return true because the left-hand side of the `||` is false.

If `false` is a valid value, then you cannot use the `||` trick - you have to be explicit:

```auto
var SetTempCFirstOn = context.get('SetTempCFirstOn');
if (SetTempCFirstOn === undefined) {
    SetTempCFirstOn = true
}

```

Please also read this post about how to share code/flows in the forum - [How to share code or flow json](https://discourse.nodered.org/t/how-to-share-code-or-flow-json/506)

---

_[View the full topic](https://discourse.nodered.org/t/strange-behaviour-of-assign-of-context-var-with-init-bool-value/9026)._
