I'm reading through the jQuery source code for jQuery.filter and I stumbled upon this heaping pile of
jQuery.filter = function( expr, elems, not ) {
var elem = elems[ 0 ];
if ( not ) {
expr = ":not(" + expr + ")";
}
return elems.length === 1 && elem.nodeType === 1 ?
jQuery.find.matchesSelector( elem, expr ) ? [ elem ] : [] :
jQuery.find.matches( expr, jQuery.grep( elems, function( elem ) {
return elem.nodeType === 1;
}));
};
So in short we have
return "a" && "b" ? "c" ? "d" : "e" : "f";
where each string could be a varying value
My question isn't how to decipher this code, but my brain is tying in knots trying to evaluate the logic being used here.
Can anyone help me understand how JavaScript evaluates this return expression?
c ? d : emust be a sub-expression (there's no other meaningful way to interpret those tokens). Therefore it really comes down to whethera && b ? x : yis(a && b) ? x : yora && (b ? x : y). But surely this is solved with a trivial Google search for "javascript precedence" or similar?