0

I have an identity function:

theIdentity = function(val) {
    return val;
 };

And a function that is going to reduce an array:

theReduce = function(collection, iterator, accumulator) {
    iterator = iterator || theIdentity;
};

I am having trouble understanding this line:

iterator = iterator || theIdentity;

I know it is supposed to check if the iterator is undefined and assign it as theIdentity if it is, but anymore insight would be appreciated.

Mardymar
  • 419
  • 3
  • 14

1 Answers1

-1

It is short-hand for:

if(iterator) 
   iterator = iterator
else 
   iterator = theIdentity;
Andy T
  • 10,223
  • 5
  • 53
  • 95