$('.blocks','#grid').each(function (i) {
$(this).stop().css({opacity:0}).delay(100).animate({
'opacity': 1
}, {
duration: 2000,
complete: (i !== row * cols - 1) ||
function () {
alert('done');
}
});
});
What does the “||” operator mean in the “complete” property of the animate function?
It exploits short circuit evaluation. While the left hand side is truthy it won’t bother evaluating the right hand side.
This is because with an
OR, if one condition is truthy, it doesn’t need to bother with additional conditions because it already knows enough information to answer the condition. They are also evaluated from left to right.Also, in JavaScript, instead of the condition returning true or false, it returns the last operand it evaluated. You can see why this is useful.