# Help with function, checking a value

**URL:** https://discourse.nodered.org/t/help-with-function-checking-a-value/32938
**Category:** General
**Created:** [16 September 2020 05:09 UTC](https://discourse.nodered.org/t/help-with-function-checking-a-value/32938 "2020-09-16T05:09:32Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![BassTeQ](https://avatars.discourse-cdn.com/v4/letter/b/4bbf92/32.png) [@BassTeQ](https://discourse.nodered.org/u/BassTeQ)
#### Post date: [16 September 2020 05:09 UTC](https://discourse.nodered.org/t/help-with-function-checking-a-value/32938/1 "2020-09-16T05:09:32Z")

</div>

Hello, I'm having trouble trying to work out why this logic isn't going into the last condition **if (status == "true") {** appreciate any help

```auto
var status = msg.payload.on;
//
// used to skip the startup event
var transitiontime = msg.payload.transitiontime;
node.warn("Here " + status + ", transitiontime " + transitiontime);
if (! msg.payload.hasOwnProperty("transitiontime")) {
    node.warn("transitiontime not defined, good!")
    if (status == "true") {
        node.warn("Its TRUE : " + transitiontime)
    }
}
return msg;

```

 ![flow-issue](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/4/9/4931a2e48288e1d27c63445b407735ce89df3de8.png)

---

<div class="post-metadata">

### Author: ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)
#### Post date: [16 September 2020 06:00 UTC](https://discourse.nodered.org/t/help-with-function-checking-a-value/32938/2 "2020-09-16T06:00:22Z")

</div>

The on looks like a boolean not a string so you need (status == true) without quotes.

---

<div class="post-metadata">

### Author: ![BassTeQ](https://avatars.discourse-cdn.com/v4/letter/b/4bbf92/32.png) [@BassTeQ](https://discourse.nodered.org/u/BassTeQ)
#### Post date: [16 September 2020 06:22 UTC](https://discourse.nodered.org/t/help-with-function-checking-a-value/32938/3 "2020-09-16T06:22:00Z")

</div>

Thanks very much, this did the trick

**if (status === true) {**

Cheers

---

<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: [16 September 2020 08:01 UTC](https://discourse.nodered.org/t/help-with-function-checking-a-value/32938/4 "2020-09-16T08:01:44Z")

</div>

You could probably also use  
`if (status) {`  
That is not _exactly_ the same as `=== true`, which will only pass the test if status is a boolean and is true. The alternative will, if given a value that is not boolean, convert it to true or false based on its value, so a variable which is undefined will count as false, and a number value 0 will count as false, but anything else is counted as true (I think, there may be others I have forgotten).  
So if your value coming is known to be a boolean true of false then you can certainly use the alternative.

---

<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: [30 September 2020 08:01 UTC](https://discourse.nodered.org/t/help-with-function-checking-a-value/32938/5 "2020-09-30T08:01:55Z")

</div>

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