Help with function, checking a value

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

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;

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

Thanks very much, this did the trick

if (status === true) {

Cheers

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.

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