ga-wdi-boston / js-functions-ins-and-outs

JavaScript Function Arguments and Return Values.
Other
2 stars 174 forks source link

Some developers confuse "callback" with "method that takes a callback" #11

Open jrhorn424 opened 8 years ago

jrhorn424 commented 8 years ago

This indicates that sometimes when we receive vague feedback about "understanding callbacks", some developers do not properly have the vocabulary in their mind. A visual diagramming of an example might help (like diagramming a sentence in English).

For example, when a developer says "the reduce callback" what they typically mean is "the reduce method", but what experienced developers would hear is "the function the reduce method receives as the first argument".

That confusion makes it impossible to explain what a callback is until the more experienced developer recognizes the mistake.

[1,2,3].reduce((a, b) => { return a + b; });
//        ^---- referred to as callback, therefor:
//        when we say callbacks are "arguments to functions" they get confused
jrhorn424 commented 7 years ago

@MicFin Please note this.

Additionally, ask everyone the same question using cold-call cards. Trust me. It sounds silly. Do it.

"What is a callback?"

"A callback is a function that is passed to another function."

This is all. They will think it is a trick. They will think there's more they don't get. It's definitional. Callbacks are not special. They are types passed to a function that accesses those values in the body (invokes the callback in the body). It's just like everything else you can do with a function, whether it's passing a primitive or a reference type.

jrhorn424 commented 7 years ago

We'll do a deep dive on asynchrony later.