Assignment in conditional expression

Hi
wehr is my error?

var gridpower=flow.get('gridpower') || 0;

if (msg.payload =1 && gridpower !=0){
    msg.payload=0;
}
I always become the yellow question mark with assignment in conditional expression in front of :  if (msg.payload =1 && gridpower !=0){

Hi @edstobi

What that warning is telling you is that in your if statement, you are setting the value of msg.payload to 1, rather than testing its value.

In JavaScript, to compare a value you use ===:

if (msg.payload === 1 && gridpower != 0){

And Just for completeness:



1 Like

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