What does the operator |= do in JavaScript?

后端 未结 4 1553
感动是毒
感动是毒 2020-12-04 17:29

I found the following code in a JS project:

var a = new Array();
a[0] = 0;
for (var b = 0; b < 10; b++) {
  a[0] |= b; 
}

What does the

4条回答
  •  Happy的楠姐
    2020-12-04 18:27

    Returns a one in each bit position for which the corresponding bits of either or both operands are ones.

    Code: result = a | b;

    ^ is the bitwise XOR operator, which returns a one for each position where one (not both) of the corresponding bits of its operands is a one. The next example returns 4 (0100):

提交回复
热议问题