简体   繁体   中英

What is the difference between “>>>” and “>>” in JavaScript?

I have just found a piece of JS code that uses >>> instead of >> .

I have searched Stack Overflow and also Google, but I've found documentation only for >> operator.

After a few tests they look the same. Both operators are doing a binary right shift. Trying to use <<< fails with a syntax error.

Is this an exception in the JS's interpreter that allows us to use >>> also ?

PS: I've tried using >>>> but it fails with a syntax error, so something must be different.

This operator >>> is unsigned right shift which shifts the first operand the specified number of bits to the right. Excess bits shifted off to the right are discarded. Zero bits are shifted in from the left. The sign bit becomes 0, so the result is always non-negative. As You've tried <<< (assuming you mean left unsigned shift) which is logically incorrect as there's no signed bit at the end. For more information please use this link

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM