I was going through some stuff in the jQuery source, specifically the inArray method and I found this line of code:
i = i ? i < 0 ? Math.max( 0, len + i ) : i : 0;
What I am seeing is two ternary operators, but I have no idea how this is used. I understand how the ternary operator works, but I have never seen it used like this before. How does this piece of code work??
Just break it down like you would
1 + 2 + 3:In fact, that whole line seems inefficient to me. Personally I’d just use: