Value 0 not considered

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?

first node

flow.set("tempEsternaMinPrec", 0);

second node

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;

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

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

Needs nodejs 14+

3 Likes

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

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