# Why is the result always false?

**URL:** <https://discourse.nodered.org/t/why-is-the-result-always-false/56808>\
**Category:** General\
**Created:** [17 January 2022 14:39 UTC](https://discourse.nodered.org/t/why-is-the-result-always-false/56808 "2022-01-17T14:39:34Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![hermiot](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/hermiot/32/28140_2.png) [@hermiot](https://discourse.nodered.org/u/hermiot)\
**Post date:** [17 January 2022 14:39 UTC](https://discourse.nodered.org/t/why-is-the-result-always-false/56808/1 "2022-01-17T14:39:34Z")

</div>

Hi,

why is the output always false instead of true, as it is defined?

```auto
var CO2 = msg.payload;

var L1 = {
  payload: {
    On: msg.payload.On === true}}

var L2 = {
  payload: {
    On: msg.payload.On === true}}

var L3 = {
  payload: {
    On: msg.payload.On === true}}

var L4 = {
  payload: {
    On: msg.payload.On === true}}

if (CO2 > 1600){ 
    return [null, null, L4];
    }
else if (CO2 > 1200){
    return [null, L3, null];
    }
else if (CO2 < 650){
    return [L2, null, null];
    }

```

Debug Output:

```auto
msg.payload : Object
object
On: false

```

Thanks for helping!

---

<div class="post-metadata">

**Author:** ![shrickus](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/shrickus/32/517_2.png) [@shrickus](https://discourse.nodered.org/u/shrickus)\
**Post date:** [17 January 2022 14:53 UTC](https://discourse.nodered.org/t/why-is-the-result-always-false/56808/2 "2022-01-17T14:53:26Z")

</div>

I see a couple potential issues here -- but without some sample input data, it's just a guess...

> [@hermiot](#):
>
> `msg.payload.On === true`

Using the triple equal operator forces JS to compare both the value and datatype for equality. So if you expect the output should be `true`, then I suspect your incoming value is the **string**"true", not a boolean. If you use the more forgiving `==` operator, then you may get what you expect.

> [@hermiot](#):
>
> ```auto
> var CO2 = msg.payload;
> 
> ```

> [@hermiot](#):
>
> ```auto
> if (CO2 > 1600){ 
> 
> ```

In the previous code you are trying to access the field `payload.On` which means your payload is an Object, not a number. So you cannot compare any object to a number and get a truthy value.

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [17 January 2022 14:59 UTC](https://discourse.nodered.org/t/why-is-the-result-always-false/56808/3 "2022-01-17T14:59:04Z")

</div>

Also, if you click on`object` in the debug pane it will expand it so you can see what is there.

---

<div class="post-metadata">

**Author:** ![hermiot](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/hermiot/32/28140_2.png) [@hermiot](https://discourse.nodered.org/u/hermiot)\
**Post date:** [18 January 2022 13:11 UTC](https://discourse.nodered.org/t/why-is-the-result-always-false/56808/4 "2022-01-18T13:11:46Z")

</div>

Hi,

you pointed me to the solution. I wanted to set the msg.payload.On to true. So a simple "=" solved it...

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:** [19 March 2022 13:11 UTC](https://discourse.nodered.org/t/why-is-the-result-always-false/56808/5 "2022-03-19T13:11:55Z")

</div>

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