Looking at this piece of code:
for (var i = 0, f; f = families[i]; i++) {
}
I haven’t actually seen a loop like this before and I want to be sure I understand it correctly.
Am I correct in assuming that if families.length == 2 that the 2nd part of the for line would return false on f = families[2]?
I would have thought it would need to be something like f == families[2] in order to return false.
f = families[i]is an expression that returns the value offamilies[i]. (It also has the side-effect of assigning that value tof)If
families.length === 2thenfamilies[2] === undefinedthus the expression returnsundefinedwhich is falsey and breaks the loop.For more hacking fun you can turn
into
You may have to string replace
;with,and string replaceiwithi-1. You also just murdered readability.It should also be pointed out that the for loop is silly for readability.
Is significantly more readable.