0

I see the below code inside GoogleChrome/puppeteer:

    this._modifiers &= ~this._modifierBit(description.key);

you can find in this file: code.

And my question is why use &=, and how it works?

Saeed Jalali
  • 416
  • 4
  • 16
  • All you need to know is in https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Bitwise_Operators Hard to hammer close as dupe though because you asked for multiple operators, but for `&` this [Q/A](https://stackoverflow.com/questions/47802087/what-mathematical-function-does-bitwise-and-operator-do-js/47802203), for `~` [this one](https://stackoverflow.com/questions/4295578/explanation-of-bitwise-not-operator) – Kaiido Sep 17 '18 at 08:17

1 Answers1

1

this._modifiers &= ~this._modifierBit(description.key); is a short hand of

this._modifiers = this._modifiers & ~this._modifierBit(description.key);

It depends on the coding style you opt to chose as both of them have same complexity based on computation. That is just a shorthand feature supported by the programming language. Some more examples are:

a += 10 equivalent to a = a+10
a *= 10 equivalent to a = a*10
Ankit Agarwal
  • 30,378
  • 5
  • 37
  • 62