# Value 0 not considered

**URL:** https://discourse.nodered.org/t/value-0-not-considered/74413
**Category:** General
**Created:** [30 January 2023 12:34 UTC](https://discourse.nodered.org/t/value-0-not-considered/74413 "2023-01-30T12:34:38Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![Giamma](https://avatars.discourse-cdn.com/v4/letter/g/e47774/32.png) [@Giamma](https://discourse.nodered.org/u/Giamma)
#### Post date: [30 January 2023 12:34 UTC](https://discourse.nodered.org/t/value-0-not-considered/74413/1 "2023-01-30T12:34:38Z")

</div>

I try to explain ....  
In my dashboard I show the current temperature and the lowest temperature of the day.  
This morning the current temperature was 0 and I set the var tempEsternaMinPrec to 0 because it was the lowest temperature of the day.  
When the temperature is increased to 0.1 the var tempEsternaMinPrec had to remain to 0 but the second function is failed because the value temp is set to 30 and not 0.  
if I delete the default value (30) then the function works fine ....

Where is the problem?

 ![img01](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/c/2/c21ebc30aef19a2e516ada60014588947899c4e2.png)

first node

```auto
flow.set("tempEsternaMinPrec", 0);

```

second node

```auto
const output = [null];

const temp = flow.get("tempEsternaMinPrec") || 30
node.status(temp)
const x = 0.1

if (x < temp) {
    
    output[0] = { payload: x }
}

return output;

```

---

<div class="post-metadata">

### Author: ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)
#### Post date: [30 January 2023 12:40 UTC](https://discourse.nodered.org/t/value-0-not-considered/74413/2 "2023-01-30T12:40:55Z")

</div>

> [@Giamma](#):
>
> ```auto
> const temp = flow.get("tempEsternaMinPrec") || 30
> 
> ```

0 is considered falsy so the above, if the flow.get returns 0, it will set to 30.  
try below, as it's a test for nullish values.  
[Nullish coalescing operator (??) - JavaScript | MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Nullish_coalescing)

```auto
const temp = flow.get("tempEsternaMinPrec") ?? 30

```

Needs nodejs 14+

---

<div class="post-metadata">

### Author: ![Giamma](https://avatars.discourse-cdn.com/v4/letter/g/e47774/32.png) [@Giamma](https://discourse.nodered.org/u/Giamma)
#### Post date: [30 January 2023 12:51 UTC](https://discourse.nodered.org/t/value-0-not-considered/74413/3 "2023-01-30T12:51:49Z")

</div>

It's works fine .... thank you very much!

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)
#### Post date: [13 February 2023 12:52 UTC](https://discourse.nodered.org/t/value-0-not-considered/74413/4 "2023-02-13T12:52:11Z")

</div>

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.
