# Context set/get syntax question

**URL:** <https://discourse.nodered.org/t/context-set-get-syntax-question/19368>\
**Category:** General\
**Created:** [19 December 2019 23:02 UTC](https://discourse.nodered.org/t/context-set-get-syntax-question/19368 "2019-12-19T23:02:51Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![drmibell](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/drmibell/32/8424_2.png) [@drmibell](https://discourse.nodered.org/u/drmibell)\
**Post date:** [19 December 2019 23:02 UTC](https://discourse.nodered.org/t/context-set-get-syntax-question/19368/1 "2019-12-19T23:02:51Z")

</div>

In `function` nodes I often use patterns like

```auto
let startup = true;
context.set('startup',startup);

```

or

```auto
context.set('startup',true);
let startup = context.get('startup');

```

As far as I can tell, these can be replaced by the single instruction,

`let startup = context.set('startup',true);`

but I wonder whether this is strictly cricket in terms of JS syntax and the NR implementation of context storage. Any comments?

---

<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:** [19 December 2019 23:13 UTC](https://discourse.nodered.org/t/context-set-get-syntax-question/19368/2 "2019-12-19T23:13:07Z")

</div>

> [@drmibell](#):
>
> As far as I can tell, these can be replaced by the single instruction,
> 
> `let startup = context.set('startup',true);`
> 
> but I wonder whether this is strictly cricket in terms of JS syntax and the NR implementation of context storage. Any comments?

The `context.set()` api does not return the value you set, so I'm not sure why that is working for you. It certainly doesn't work when I try it here.

---

<div class="post-metadata">

**Author:** ![drmibell](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/drmibell/32/8424_2.png) [@drmibell](https://discourse.nodered.org/u/drmibell)\
**Post date:** [19 December 2019 23:16 UTC](https://discourse.nodered.org/t/context-set-get-syntax-question/19368/3 "2019-12-19T23:16:39Z")

</div>

> [@knolleary](#):
>
> The `context.set()` api does not return the value you set

I suspected that, so I'm as puzzled as you are. I'll try to figure out why it seems to work.

---

<div class="post-metadata">

**Author:** ![drmibell](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/drmibell/32/8424_2.png) [@drmibell](https://discourse.nodered.org/u/drmibell)\
**Post date:** [19 December 2019 23:40 UTC](https://discourse.nodered.org/t/context-set-get-syntax-question/19368/4 "2019-12-19T23:40:26Z")

</div>

OK. I was fooling myself by checking the value with

`node.warn(context.get('startup'));`

instead of

`node.warn(startup);`

My bad. ☹

Would it be a bad idea to allow `context.set()` to return a value?

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [20 December 2019 00:49 UTC](https://discourse.nodered.org/t/context-set-get-syntax-question/19368/5 "2019-12-20T00:49:27Z")

</div>

> [@drmibell](#):
>
> Would it be a bad idea to allow `context.set()` to return a value?

if it did wouldn't you want it to return a variation of 'success' or ''failed' 😁
