What exactly does the >>= operator mean in JavaScript? I mean, I use it often in Haskell to work with monadic values, but I saw this weird (and syntactically valid!) operator in a JavaScript code:
function repeatArray$(arr, n){
for (var r = []; n > 0; (n >>= 1) && (arr = arr.concat(arr)))
if (n & 1) r.push.apply(r, arr);
return r;
}
I know what the function does, but I can't resolve the utility here or what it can do. Is it a composition of two operators, such as --> (-- >) with bitwise operations? I didn't find a specification about that.
x >>= y is Right Shift assignment. Equivalent to x = x >> y.
MDN Assignment Operators
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With