Javascript bitwise AND (&=) changes variable
Categories
(Firefox :: Untriaged, defect)
Tracking
()
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)}
Comment 1•1 year ago
|
||
&= is an assignment operator. See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Bitwise_AND_assignment
Sorry, you are right, this is duff information from W3schools. bitwise and is & and not &=
Description
•