Mastering JavaScript Callbacks




Learn how to manage asynchronous callbacks and avoid callback hell.

Getting started with Node.js / io.js: https://www.youtube.com/watch?v=Ads1A7pn2LI

Code examples used in this video: https://github.com/shama/letswritecode/tree/master/mastering-callbacks

Original source


30 responses to “Mastering JavaScript Callbacks”

  1. At 13:00, would there be any advantage to changing the function 'loadBears' to something like this:
    function loadBears(bear){…}
    And then onLoad calling loadBears with bears.shift() as a parameter?

  2. fs.readfile(filepath,function(err, bears){
    if(err) return done(err)
    }

    If there is err in above code, will done cb be executed with err parameter and we get the error message OR

    it will just return the done cb with err something like:

    var returnvalue= getBears('bears.txt',function(err,bears)
    {
    console.log(bears);
    }
    and after we can execute:
    returnvalue();

  3. At first I thought this is a really complicated example because i am new to functional programming, but then after watching this video over and over many times , and after doing different operations through different .txt files, i really understood callback functions. Love this video! For people who are completely new to functional programming, I would suggest watching a few beginner videos about .filter function, .map function, .reduce function, beginner videos about callback functions and working out a few basic examples on them (really important) and then watching this video to gain perfection on callbacks. This video is aptly titled 'Mastering JavaScript Callbacks'

  4. Please explain how it works more that why we use it. As someone from Java, I'm completely lost.
    function(err, bears) { *stuff*} <– who, what, when, where, why?function(err, dict) { *stuff*}what are these values? can I use them outside the nested pile of code?

  5. Kyle, that was an amazing video. I had a question though. Is the stuff written inside these functions synchronous ? Consider the compareBears function. Does the bear line run after the dict line, is that part synchronous ?

  6. Love the tut, but had to watch in a few times, and pause in places to follow.

    You're obviously a guru, I think maybe you're moving a little to quickly for this to be easy to follow.

    For the rest of you who don't agree… you're guru's as well.

    LOL Loved the tut… can't wait to see more.

  7. Dude, you're focusing too much on doing logic for your bears and nothing in the synchronous and asynchronous calls. Please try to think about the people who really would like to learn and master those calls. Thanks

  8. where can i watch the video that explains the image() function being called? is there a way to show an image to the screen without having to include an image() function?

  9. I notice you don't use semicolon in your javascript. Is this a good practice? Do you have any comments or idea behind your habit? Or did you read any article regarding this?
    By the way, nice tutorial!

  10. I really enjoyed this video and these are great examples of callbacks, but it would have been nice to have a better explanation of callbacks themselves. Also, it would have been nice to see a few refreshes of the browser to demonstrate the bears loading in different orders. Or perhaps they never will because the file sizes don't change? Not sure…

Leave a Reply