# Assignment in conditional expression

**URL:** <https://discourse.nodered.org/t/assignment-in-conditional-expression/87202>\
**Category:** General\
**Created:** [12 April 2024 16:33 UTC](https://discourse.nodered.org/t/assignment-in-conditional-expression/87202 "2024-04-12T16:33:44Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![edstobi](https://avatars.discourse-cdn.com/v4/letter/e/aca169/32.png) [@edstobi](https://discourse.nodered.org/u/edstobi)\
**Post date:** [12 April 2024 16:33 UTC](https://discourse.nodered.org/t/assignment-in-conditional-expression/87202/1 "2024-04-12T16:33:44Z")

</div>

Hi  
wehr is my error?

```auto
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){

```

---

<div class="post-metadata">

**Author:** ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)\
**Post date:** [12 April 2024 16:38 UTC](https://discourse.nodered.org/t/assignment-in-conditional-expression/87202/2 "2024-04-12T16:38:08Z")

</div>

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 `===`:

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

```

---

<div class="post-metadata">

**Author:** ![marcus-j-davies](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/marcus-j-davies/32/103435_2.png) [@marcus-j-davies](https://discourse.nodered.org/u/marcus-j-davies)\
**Post date:** [12 April 2024 16:46 UTC](https://discourse.nodered.org/t/assignment-in-conditional-expression/87202/3 "2024-04-12T16:46:22Z")

</div>

And Just for completeness:

> **[JavaScript Operators Reference](https://www.w3schools.com/jsref/jsref_operators.asp)**
>
> W3Schools offers free online tutorials, references and exercises in all the major languages of the web. Covering popular subjects like HTML, CSS, JavaScript, Python, SQL, Java, and many, many more.

 ![Screenshot 2024-04-12 at 17.45.38](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/4/9/49a3a51dee215f7c967c9f144c0c1b9b97b71208.png)  
 ![Screenshot 2024-04-12 at 17.45.07](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/7/a/7a2fdd8126897b9ed884793bf714af888abf0cc2.png)  
 ![Screenshot 2024-04-12 at 17.46.05](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/1/b/1b1b5e8e02f90e4dcc7d48f713b1591262df6aec.png)

---

<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:** [26 April 2024 16:46 UTC](https://discourse.nodered.org/t/assignment-in-conditional-expression/87202/4 "2024-04-26T16:46:53Z")

</div>

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