# Bitwise syntax error ("error in JavaScript code")

**URL:** <https://discourse.nodered.org/t/bitwise-syntax-error-error-in-javascript-code/68466>\
**Category:** General\
**Created:** [1 October 2022 18:36 UTC](https://discourse.nodered.org/t/bitwise-syntax-error-error-in-javascript-code/68466 "2022-10-01T18:36:39Z")\
**Posts on this page:** 5\
**Page:** 2

<div class="post-metadata">

**Author:** ![Frida](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/frida/32/68250_2.png) [@Frida](https://discourse.nodered.org/u/Frida)\
**Post date:** [3 October 2022 14:23 UTC](https://discourse.nodered.org/t/bitwise-syntax-error-error-in-javascript-code/68466/21 "2022-10-03T14:23:15Z")

</div>

![pic02](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/3/7/379f7a7510fdc24880930a2d3b345cecb5317b23.png)

---

<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:** [3 October 2022 14:38 UTC](https://discourse.nodered.org/t/bitwise-syntax-error-error-in-javascript-code/68466/22 "2022-10-03T14:38:58Z")

</div>

As we have said multiple times, that line should be  
`msg.zone = ((msg.payload[1 + 1] >> 2) & 1) == 1`  
if you want true/false, or  
`msg.zone = (msg.payload[1 + 1] >> 2) & 1`  
if you want 1/0

---

<div class="post-metadata">

**Author:** ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)\
**Post date:** [4 October 2022 00:13 UTC](https://discourse.nodered.org/t/bitwise-syntax-error-error-in-javascript-code/68466/23 "2022-10-04T00:13:03Z")

</div>

> [@Steve-Mcl](#):
>
> The right hand part `(0x01 == 0x01)` evaluates to a Boolean & cannot be used with the bitwise `&` operator.

Urm, actually it can according to MDN which states that the bitwise operators convert their operands to 32bit integers. As I've previously stated several times now, that makes `(0x01 == 0x01)` === `true` === `1`.

So that means that Monaco is being somewhat boorish here by showing an error when it should be showing a warning.

Non-the-less, again, as stated many times now, the original equation does not make sense and doesn't do what was intended.

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [4 October 2022 06:04 UTC](https://discourse.nodered.org/t/bitwise-syntax-error-error-in-javascript-code/68466/24 "2022-10-04T06:04:01Z")

</div>

> [@TotallyInformation](#):
>
> So that means that Monaco is being somewhat boorish here by showing an error when it should be showing a warning

Yeah that's what I meant Julian. I should probably have been more explicit.

---

<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:** [3 December 2022 06:04 UTC](https://discourse.nodered.org/t/bitwise-syntax-error-error-in-javascript-code/68466/25 "2022-12-03T06:04:27Z")

</div>

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

[Previous page](https://discourse.nodered.org/t/bitwise-syntax-error-error-in-javascript-code/68466.md?page=1)
