0

index is a number. I do not understand what >> is in JavaScript.

setIndex: function(index) {

    var i = this.index;
    this.index = index >> 0; // ?????

    if (this.index < 0) {
    this.index = 0;

    } else if (this.index >= this.config.items.length) {
    this.index = this.config.items.length - 1;
    }

    return (i !== this.index);
}
Anthony Grist
  • 38,173
  • 8
  • 62
  • 76
GibboK
  • 71,848
  • 143
  • 435
  • 658
  • https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Bitwise_Operators – PeeHaa Aug 09 '13 at 09:26
  • @Quentin Can you explain what use there would be in shifting the value by 0 bits? That's not explained in the question you linked to. – JLRishe Aug 09 '13 at 09:28
  • thanks guys for posting other similar questions, I was not aware of.. thanks – GibboK Aug 09 '13 at 09:29
  • 1
    I suspect what it's actually being used here for is to ensure that index is a number rather than a string. It would be more understandable if it was `this.index = +this.index` though I reckon. – Doug Aug 09 '13 at 09:31
  • The intent is `this.index = (int32)index`. `+this.index` doesn't do anything to something that is already a number. – Esailija Aug 09 '13 at 10:39

1 Answers1

2

x >> y means to shift the bits of x by y places to the right (<< means shift to the left).

Read more about bitwise operators and see some examples here.

Stefan
  • 5,644
  • 4
  • 24
  • 31
Joetjah
  • 6,292
  • 8
  • 55
  • 90