I have a payload which is either boolean true or false. However, sometimes the request times out and an error code is returned as payload which is a negative integer. I'm trying to write a one line if clause in my function node to process the boolean value but not enter the clause if the value is non-integer.
I think
if (msg.payload == true || msg.payload == false) // value is boolean
{
do some processing
}
// the evaluation of true or false failed and the processing did not happen
should work but is there a way of doing something like:
if (msg.payload || !msg.payload) // value is boolean
{
do some processing
}
to evaluate the payload as true or false?
Not explaining to well, but any help would be appreciated. Ta
That would have worked if you had used triple = if (msg.payload === true || msg.payload === false)
That tells javascript to test for exactly those values. Otherwise it will do type conversion to test it.