Closed Bug 1891298 Opened 1 year ago Closed 1 year ago

Javascript bitwise AND (&=) changes variable

Categories

(Firefox :: Untriaged, defect)

defect

Tracking

()

RESOLVED INVALID

People

(Reporter: mike, Unassigned)

Details

User Agent: Mozilla/5.0 (X11; Linux x86_64; rv:109.0) Gecko/20100101 Firefox/115.0

Steps to reproduce:

<script>
let x =7;

document.getElementById("demo").innerHTML =
(x &= 1) + "<br>" +
(x &= 2 )+ "<br>" +
(x &=4)+ "<br>" +
(x );
</script>

Actual results:

After the first bitwise operation, variable x is set to 1 (i.e. the result). The Value of x should not be changed by this test, as it then fails the next 2 tests which it should pass. The result is :
1
0
0
0

Expected results:

The result should have been :
1
2
4
7
{Version 115.9.1esr (64 bit)}

Status: UNCONFIRMED → RESOLVED
Closed: 1 year ago
Resolution: --- → INVALID

Sorry, you are right, this is duff information from W3schools. bitwise and is & and not &=

You need to log in before you can comment on or make changes to this bug.