Computer programming, more than any other creative activity, stimulates the part in each of us that seeks to navigate through time by following strict rules. And one of the most delicious parts of learning to program involves learning those rules by trial and error. Programming becomes a game in this way. Today, my colleague and I spent well over an hour looking for a problem with our code. Rectifying it, at long last, we had stumbled blindly upon a feature of JavaScript so obvious that we we could not imagine how we had progressed so far without it.

Functions usually take parameters and when they do, order matters.

In our divide function, swapping the parameters x and y is tantamount to swapping dividend and divisor.

In our changeArrayElements function, however, the nature of the two parameters are so different that it might be reasonable to assume that the function would know which argument to use as a function and which to use as an array. Not so.

Each parameter is treated in the order each appears in the arguments list. So the interpreter will go ahead and try to iterate over a callback function and apply an array to each “element” of of a callback function.

Bottom line, keep your arguments in order, which is especially important when currying.