0

Today i reading some article on MDN and find something new to me.in this link on line 11 i find some thing like this :

 var t = Object( this ), len = t.length >>> 0, k = 0, value;

the full code is :

if ( 'function' !== typeof Array.prototype.reduce ) {
 Array.prototype.reduce = function( callback /*, initialValue*/ ) {
'use strict';
if ( null === this || 'undefined' === typeof this ) {
  throw new TypeError(
     'Array.prototype.reduce called on null or undefined' );
}
if ( 'function' !== typeof callback ) {
  throw new TypeError( callback + ' is not a function' );
}
var t = Object( this ), len = t.length >>> 0, k = 0, value;
if ( arguments.length >= 2 ) {
  value = arguments[1];
} else {
  while ( k < len && ! k in t ) k++; 
  if ( k >= len )
    throw new TypeError('Reduce of empty array with no initial value');
  value = t[ k++ ];
}
for ( ; k < len ; k++ ) {
  if ( k in t ) {
     value = callback( value, t[k], k, t );
  }
}
return value;
};
}

so what measns >>> character in line 11.

MBehtemam
  • 6,516
  • 11
  • 56
  • 98
  • 2
    [Zero-fill right shift operator](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Bitwise_Operators#Unsigned_right_shift). – Frédéric Hamidi Jun 19 '14 at 07:45

1 Answers1

0

>>> is the zero fill right shift operator. https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Operators/Bitwise_Operators#Unsigned_right_shift

In order to use the operator JavaScript has to convert the argument into an integer. Shift by 0 bits has no effect on an integer, so in this program the shift is used only to ensure the correct type.

Joni
  • 101,441
  • 12
  • 123
  • 178