Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the >>>= operator in Javascript?

What does the following Javascript statement do to a?

a >>>= b;
like image 385
Josh Stodola Avatar asked Oct 27 '09 20:10

Josh Stodola


People also ask

What is ++ operator in JavaScript?

The increment operator ( ++ ) increments (adds one to) its operand and returns the value before or after the increment, depending on where the operator is placed.

What does '!' Mean in JavaScript?

The ! symbol is used to indicate whether the expression defined is false or not. For example, !( 5==4) would return true , since 5 is not equal to 4. The equivalent in English would be not .

What type of operator is JavaScript?

JavaScript includes various categories of operators: Arithmetic operators, Comparison operators, Logical operators, Assignment operators, Conditional operators.

How many operators are there in JavaScript?

JavaScript Operators are as rich as what you'd expect from any modern language. There are four categories: arithmetic, comparison, assignment, and logical.


3 Answers

It does the same thing as this:

a = a >>> b;

Except that a is only evaluated once (which has observable difference if its evaluation involves any side effects).

And >>> is unsigned (logical) right shift.

like image 59
Pavel Minaev Avatar answered Oct 06 '22 16:10

Pavel Minaev


I right shifts the value in a the number of bits specified by the value in b, without maintaining the sign.

It's like the >>= operator that rights shifts a value, only that one does not change the sign of the number.

Example:

var a = -1;

// a now contains -1, or 11111111 11111111 11111111 11111111 binary

var b = 1;
a >>>= b;

// a now contains 2147483647, or 01111111 11111111 11111111 11111111 binary.
like image 22
Guffa Avatar answered Oct 06 '22 15:10

Guffa


It's a bitwise operator called zero-fill right shift. It will shift the binary representation of a to the right by b places, and replace the empty items with zeros. Then the result will be assigned to a.

like image 22
Jacob Mattison Avatar answered Oct 06 '22 15:10

Jacob Mattison