Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript

Anthony c
Anthony c
20,907 Points

Detailing the difference between callbacks vs promises in a simple table?

I'm wondering if there is a visual representation of the difference between a callback and promise.

Something similar to how they are comparing paas/saas/iaas:

http://image.slidesharecdn.com/chapter4-141011091531-conversion-gate01/95/fundamental-conceptsandmodels-cloud-computing-24-638.jpg?cb=1413019196

Does this exist? Is there somebody on the forum willing to put this together? I think it would help me (and I'm sure others). I've read through about 20+ quora/SO/blog posts that do a really poor job of answering this question succinctly... I find 90% of coders are really bad at communicating (no offense coders, just saying... here's an example of your typical SO answer when somebody asks for very plain english: http://stackoverflow.com/questions/9596276/how-to-explain-callbacks-in-plain-english-how-are-they-different-from-calling-o)

Anyway, maybe some points of difference (or similarity) to map out in this table might be:

  1. GOALS:

callback: to get around the non-blocking nature of javascript

promises: to get around the non-blocking nature of javascript

  1. CODE PATTERN:

callback: [no clue]

promises: uses then keyword

  1. CODING SITUATION #1:

callback: you don't want to use a callback here because of X

promise: you want to use a callback here because of Y

  1. CODING SITUATION #2:

callback: you want to use a callback here because of X

promise: you don't want to use a callback here because of Y

  1. [INSERT OTHER POINT OF SIMILARITY OR DIFFERENCE]:

callback: ....

promise: ....

so on and so forth....

Anybody up for the challenge!? You could even make a blog post out of it if you have personal blog.

1 Answer

Anthony c
Anthony c
20,907 Points

This seems to be one of the few solid explanations of callbacks on the internet:

http://dreamerslab.com/blog/en/javascript-callbacks/