Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does operator >>= mean

Tags:

javascript

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.

like image 791
Marcelo Camargo Avatar asked Feb 15 '26 07:02

Marcelo Camargo


1 Answers

x >>= y is Right Shift assignment. Equivalent to x = x >> y.

MDN Assignment Operators

like image 67
Miguel Mota Avatar answered Feb 16 '26 21:02

Miguel Mota



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!