Understanding JavaScript Callbacks

แชร์
ฝัง
  • เผยแพร่เมื่อ 15 ต.ค. 2024
  • Callbacks are fundamental to asynchronous coding in JavaScript. In this tutorial we delve into callbacks and look at several examples to help you understand them better.
    Would you like to help keep this channel going?
    / allthingsjavascript
    Access to EVERY course for one low price: allthingsjavas...
    For more resources on JavaScript:
    www.allthingsja...
    Access to EVERY course (get 2 months free): www.skillshare...
    Courses offered on Udemy at a discount (access from my site): allthingsjavasc...
    Tutorials referred to in this video:
    Function Expression vs. Function Declaration: • Function Declarations ...
    Closure: • Demystifying JavaScrip...
    Higher Order Functions: • Higher Order Functions...
    Avoiding Global Variables: • Three Techniques for A...
    • What is Wrong with Glo...
    #javascript #AllThingsJavaScriptLLC

ความคิดเห็น • 213

  • @ayasswain
    @ayasswain 4 ปีที่แล้ว +48

    One if the best explanation on callbacks on TH-cam.

  • @scottonanski4173
    @scottonanski4173 2 ปีที่แล้ว

    Finally! My goodness. You're the only person I've seen that's been able to explain this clearly.

  • @seenuvasanv
    @seenuvasanv 6 ปีที่แล้ว +44

    Your voice is Crystal clear...

    • @Buksiprezentz
      @Buksiprezentz 3 ปีที่แล้ว

      but his keyboard sounds crappy :)

  • @UrCristiano-x8v
    @UrCristiano-x8v 2 ปีที่แล้ว

    After so many tutorials on TH-cam now i understand calkback functions, thanks man.

  • @richochet
    @richochet ปีที่แล้ว +1

    This may be old but it's brilliant, I have been trying to get my head around callbacks, this has helped no end.
    Thank you

  • @scottmenteith4778
    @scottmenteith4778 6 ปีที่แล้ว +12

    After looking for a video that explains callbacks clearly, I finally found one! Thanks for taking the time and for your examples. I particularly liked how you built on your example so it made sense.

  • @mastle313
    @mastle313 3 ปีที่แล้ว

    Can't express how thankful I am for this video. Read several articles on callbacks but none of them helped me understand this concept as good as this video did

  • @dan110024
    @dan110024 3 ปีที่แล้ว +1

    Even the other great youtube teachers didn't explain it this well!

  • @dragomirdosen3964
    @dragomirdosen3964 4 ปีที่แล้ว +1

    Only video that explains callback's in a simple, down to earth way.

  • @mounaramesh
    @mounaramesh 6 ปีที่แล้ว +6

    Both beginners and expertise will love your explanation

  • @ryanregis99
    @ryanregis99 3 ปีที่แล้ว +4

    I didn’t notice that callbacks are what I was using in my code, I just called them referencial self-defined functions. I also never used anonymous functions because it clutters my code and makes it confusing for me to read. But now I understood the convenience of anonymous functions and the essence of callback functions. Thank you for this video!

  • @neowang8061
    @neowang8061 6 ปีที่แล้ว +6

    best explained javascript callback topic on TH-cam, well done, helped me so much.

  • @ismail9831
    @ismail9831 3 ปีที่แล้ว

    I’v spent several weeks searching straight forward explanations about js...Finally I found your channel!
    Thank you!!!!

  • @RakeroX
    @RakeroX 2 ปีที่แล้ว

    Was really confused with callbacks, but now I finally got it. Thank you very much!

  • @mickwhyte4204
    @mickwhyte4204 3 ปีที่แล้ว

    Yeah, definitely the 'go to guy' for all things JS on TH-cam. Thanks.

  • @raymondmichael4987
    @raymondmichael4987 6 ปีที่แล้ว +5

    As rarely as it is, this is one of the channels I subscribed after watching the video for the first time.
    Great explanation and real world examples are the things that made you have my 1+ sub.
    Keep up the good work,
    Greetings from Tanzania

  • @craigjohnstone7420
    @craigjohnstone7420 4 ปีที่แล้ว +6

    Outstanding! I was struggling with this, but this has helped a huge amount.

  • @germanduterte7110
    @germanduterte7110 4 ปีที่แล้ว

    Now I know the concept and use of call back function. After serveral months of knowing until I got this video, Thank You , I owe you for this.

  • @SuperSamsosa
    @SuperSamsosa 5 ปีที่แล้ว +10

    ok im still new to the concept. Cant say i totally got it but i got some grasp of it. Thx was helpful

  • @naurozbanu9882
    @naurozbanu9882 4 ปีที่แล้ว

    this is the best tutorial on callback so far. Many thanks.

  • @josebergues
    @josebergues 4 ปีที่แล้ว +2

    Hey Buddy, you are simply the best explaining callbacks in javascript, congratulations!

  • @suparnobhattacharya6345
    @suparnobhattacharya6345 4 ปีที่แล้ว

    this channel is very much underrated...Great video.

  • @vlknlvnt
    @vlknlvnt 3 ปีที่แล้ว

    pure and simple explanation

  • @kurono1822
    @kurono1822 3 ปีที่แล้ว

    Short and well explained, this kind of videos are the best

  • @dubbiesstep6555
    @dubbiesstep6555 4 ปีที่แล้ว +2

    I usually watch your videos at 1.25x speed, as you speak a bit slowly.
    Though, I've learnt a lot from you for which I'm thankful

  • @JustLookA7
    @JustLookA7 6 ปีที่แล้ว +1

    This channel has the clearest explanations about JS. I simply love it. Thanks for the lessons!

  • @Letsallparty2
    @Letsallparty2 5 ปีที่แล้ว +3

    Your lessons are incredible. One of the better js tutorials on here

  • @ArthurSilva-cv9xt
    @ArthurSilva-cv9xt 4 ปีที่แล้ว +2

    Amazing lesson! I loved even the keyboard sounds. They made me feel like I was the one who was typing! haha

  • @gagangupta1255
    @gagangupta1255 6 ปีที่แล้ว

    One of the best videos - explaining how to create custom callbacks and get them invoked !!

  • @reidwilliamson6477
    @reidwilliamson6477 3 ปีที่แล้ว

    Great video sir! You have a uniquely positive way of speaking that keeps me interested and positive minded at the same time.

  • @rahulpagidimarri4677
    @rahulpagidimarri4677 3 ปีที่แล้ว

    best explanation on call backs thanks

  • @abyshekhar
    @abyshekhar 3 ปีที่แล้ว

    This video confirms the answer to my question that why do we need to pass the callback as a parameter. In most of the videos and articles I have gone through callback seems to have been defined as the function being passed as a parameter although it would still work as a callback if we just call the function inside the outer function without passing as a parameter.

  • @avinashgsr
    @avinashgsr 3 ปีที่แล้ว

    Thank you very much for your clear explanation. This is one concept I found hard to get a clear picture.

  • @esorkinc4011
    @esorkinc4011 5 ปีที่แล้ว +1

    Your explanations are very concise.

  • @aDJam91
    @aDJam91 4 ปีที่แล้ว

    This is a great video for a concept that I was finding difficult to grasp! So clear.

  • @DcodeShow
    @DcodeShow 2 ปีที่แล้ว

    Your explanations are just great... Thank you sir for helping me

  • @karan_1993
    @karan_1993 2 ปีที่แล้ว +1

    Great explaination.

  • @Uzair_Anwar2299
    @Uzair_Anwar2299 3 ปีที่แล้ว

    Very clearly explained

  • @darz_k.
    @darz_k. 4 ปีที่แล้ว +1

    This is so slick - I love it

  • @BeatPoet67
    @BeatPoet67 6 ปีที่แล้ว +1

    You're a natural teacher, and your explanations are clear and to the point. I've no idea why you don't have more subscribers. Have you considered creating content for the likes of egghead.io etc? Thanks for your efforts in the meantime!

    • @AllThingsJavaScript
      @AllThingsJavaScript  6 ปีที่แล้ว +2

      Thanks for the feedback! I will have to look into egghead.

  • @yasarhussain3811
    @yasarhussain3811 4 ปีที่แล้ว +1

    Excellent Explanation thank you

  • @donnytechiera957
    @donnytechiera957 5 ปีที่แล้ว +1

    Awesome your teaching is very logic and simplified !!

  • @MrTomro
    @MrTomro 4 ปีที่แล้ว

    Short and simple explanation. Coming from C++, things like event listeners, callbacks, async functions, promises can be daunting at first, but really they are not that hard :) Thank you

  • @thedarkknight221122
    @thedarkknight221122 2 ปีที่แล้ว

    Subscribed for more. I Wanted this. Thank you so much.

  • @akkineniajay8117
    @akkineniajay8117 6 ปีที่แล้ว +2

    Very clearly explained. Thanks!

  • @FlawlessAlias
    @FlawlessAlias 3 ปีที่แล้ว

    This is a really good tutorial!

  • @MrRoman0629
    @MrRoman0629 2 ปีที่แล้ว

    Thank you for this video. It was very helpful in understanding callback. I look forward to watching your other videos. I did have a question, as I'm still learning. What is the reason for determineTotal being a function expression and processStudents being a function declaration? Could determineTotal been written as a function declaration and vice versa without issue?

    • @AllThingsJavaScript
      @AllThingsJavaScript  2 ปีที่แล้ว

      I think the processStudents and the determineTotal functions were defined as function expressions. I did pass an anonymous function when I called processStudents. Anyway, to answer your question the functions could be defined as function expressions or function declarations.

  • @sauravkumar442
    @sauravkumar442 4 ปีที่แล้ว

    this is very good tutorial for everyone .Thanks a lot

  • @derekfrost8991
    @derekfrost8991 3 ปีที่แล้ว +1

    Nice video. Text is very clear and you seem to be better than most. But you could replace your for loop with forEach for extra security.. :)

  • @waynebryant9931
    @waynebryant9931 5 ปีที่แล้ว

    Great tutorial on JavaScript callback functions. Well done!

  • @thongahuhu9362
    @thongahuhu9362 3 ปีที่แล้ว

    The best callback ever

  • @cybersyn-nh8du
    @cybersyn-nh8du 5 ปีที่แล้ว

    Great tutorial, one of the only ones out there which are simple to understand

  • @ahmadq9195
    @ahmadq9195 2 ปีที่แล้ว

    what a great explination. Thank you.

  • @agusan2847
    @agusan2847 ปีที่แล้ว

    Thanks... Finally i understand by this explanation ❤

  • @farazk9729
    @farazk9729 3 ปีที่แล้ว

    Thank you so much; very useful!

  • @md.ashikurrahmankhantushar4305
    @md.ashikurrahmankhantushar4305 3 ปีที่แล้ว

    You are a legend man!

  • @AndresGuerrero
    @AndresGuerrero 4 ปีที่แล้ว

    Great job explaining this topic 👍🏽 thanks!

  • @abdellatifanaflous8196
    @abdellatifanaflous8196 2 ปีที่แล้ว

    Thank you sir for sharing this, it's really helpful

  • @tymothylim6550
    @tymothylim6550 3 ปีที่แล้ว

    Thank you very much for this video! It was very clear and educational :)

  • @mehtabahmed6092
    @mehtabahmed6092 4 ปีที่แล้ว

    Thank you so much, I really got the concept

  • @sulmanzafar9563
    @sulmanzafar9563 4 ปีที่แล้ว

    Thanks All concepts are clear now

  • @jogoeire
    @jogoeire 4 ปีที่แล้ว

    Great tut. Subscribed

  • @fortwisers6070
    @fortwisers6070 2 ปีที่แล้ว

    Very well done

  • @anasizmaz5594
    @anasizmaz5594 4 ปีที่แล้ว

    Really Helpful

  • @AidanaDreamer
    @AidanaDreamer 5 ปีที่แล้ว +1

    Awesome explanation, thank you!

  • @Schweppese
    @Schweppese 3 ปีที่แล้ว

    Can you please tell me the Keyboard model and switches you use in this video? It sounds amazing! Also great explanation, Subscribed to your channel immediately...

    • @AllThingsJavaScript
      @AllThingsJavaScript  3 ปีที่แล้ว

      Microsoft natural ergonomic keyboard 4000. It is many years old.

  • @yourteacher4353
    @yourteacher4353 5 ปีที่แล้ว

    Brilliantly explained! Thanks a ton!

  • @watcherofsouls1587
    @watcherofsouls1587 6 ปีที่แล้ว

    I finally understand callbacks, thank you very very much! :D

  • @leegold7100
    @leegold7100 7 ปีที่แล้ว

    Great video. Clear and understandable.

  • @Luxcium
    @Luxcium 6 ปีที่แล้ว

    The sound of the voice got me hooked indeed ! I am not sure about the closure maybe I missed something but I dont see a function created from a function that have returned. A closure in programming allows the function to access values of variable included in a function that have finish executed and has returned... Through the closure's copies of their values or references, even when the function is invoked outside their scope. Normally the closure is using the value of variable created in an other function a level above which have returned a second function (the closure)
    ...

    • @AllThingsJavaScript
      @AllThingsJavaScript  6 ปีที่แล้ว

      Here is a tutorial where I talk about closures: th-cam.com/video/TznpOmv2BQM/w-d-xo.html

  • @limychelseafc
    @limychelseafc 4 ปีที่แล้ว

    I really like the way you explained it.
    Question though:
    The main reason behind putting a callback function into the processStudents function was to make it simpler and so that we do not keep repeating the code, I believe. In this case, this is like writing a map function or forEach function for the students array, am I right?
    Will be great to get what you think :)

    • @limychelseafc
      @limychelseafc 4 ปีที่แล้ว

      For example:
      ```js
      let employees = [
      {
      "id": "5f34d011f239ec23e4344a40",
      "name": "Peters",
      "phone": "+61 (843) 415-3801",
      "age": 36
      },
      {
      "id": "5f34d0113a4722913691038b",
      "name": "Janine",
      "phone": "+61 (996) 417-2976",
      "age": 24
      },
      {
      "id": "5f34d011129f528aff567df9",
      "name": "Faith",
      "phone": "+61 (984) 473-3636",
      "age": 29
      }
      ]
      let processEmployees = (employees, callback) => {
      for (let i = 0; i < employees.length; i++) {
      callback(employees[i])
      }
      }
      processEmployees(employees, function(employee) {
      console.log(`Name:${employee.name}, Age: ${employee.age}`)
      })
      // similar to:
      employees.map(employee => console.log(`Name:${employee.name}, Age: ${employee.age}`))
      ```

    • @AllThingsJavaScript
      @AllThingsJavaScript  4 ปีที่แล้ว

      The function passed in would be similar yes. And a function that uses map or foreach could be passed in.

  • @karlee8608
    @karlee8608 5 ปีที่แล้ว

    You are a genius. Please do more examples and explanations.

  • @edemduku3391
    @edemduku3391 3 ปีที่แล้ว

    thank you bunches man. thank you.

  • @nerdsum663
    @nerdsum663 ปีที่แล้ว

    Ur amazing teacher sir

  • @georgesmith3022
    @georgesmith3022 6 ปีที่แล้ว +1

    Thanks, clearly explained

  • @Gigusx
    @Gigusx 6 ปีที่แล้ว +4

    A bit confusing, especially for a beginner (I'm probably not alone, lol), but with a little practice, I'll probably get used to this concept. I struggled to understand some parts and it helped me to break things down to the point where I was able to say "okay, so that's what going on here".
    The explanation was great, so thanks! I like the fact that you used real-world examples to help us visualize, keep it up.

    • @albertlewis332
      @albertlewis332 5 ปีที่แล้ว

      How's your journey? from a fellow beginner.

    • @columcreed4352
      @columcreed4352 4 ปีที่แล้ว

      I found it confusing too. I think it is the name of the parameter "callback" that is confusing

  • @saurabhtalele1537
    @saurabhtalele1537 2 ปีที่แล้ว

    really u r great explainer.....

  • @MohammedAshraf
    @MohammedAshraf 2 ปีที่แล้ว

    Thank you

  • @Fernando-du5uj
    @Fernando-du5uj 4 ปีที่แล้ว

    This is what im looking for, how to create my own functions with callbacks, thank you alot, sir.

  • @joq6356
    @joq6356 5 ปีที่แล้ว

    Thanks for the explanation! I got confused in the second example started at 7:35 though, where was "data" defined ?

    • @AllThingsJavaScript
      @AllThingsJavaScript  5 ปีที่แล้ว +1

      data is a parameter for the function. So when the students array is passed to the function, it is stored in the data variable.

    • @joq6356
      @joq6356 5 ปีที่แล้ว

      @@AllThingsJavaScript Ah got it, thanks!

  • @ishaaqolwi8716
    @ishaaqolwi8716 4 ปีที่แล้ว

    Hold up, in 4:34 you said that "this is our first example of a callback". However, you did make a callback at the beginning of the video, so how come this is the first example of a callback and not the second one? Thanks

    • @AllThingsJavaScript
      @AllThingsJavaScript  4 ปีที่แล้ว

      It was kind of the same example, but you could call it a second example as we modified the way we did setTimeout.

    • @ishaaqolwi8716
      @ishaaqolwi8716 4 ปีที่แล้ว

      @@AllThingsJavaScript I see. Thanks!

  • @Bayo106
    @Bayo106 4 ปีที่แล้ว +2

    the event listener example showed me that I already really understand callbacks! Thanks for this!

  • @dav1tt
    @dav1tt 4 ปีที่แล้ว

    I dont understand last function, because if we imagine it as async function it will log "Total score: 0 - Total Count: 0" then it will call callback function. Aren't we using callbacks while we have async function?

    • @AllThingsJavaScript
      @AllThingsJavaScript  4 ปีที่แล้ว

      Callbacks are required for asynchronous JavaScript yes, but that is not their only application.

  • @evoktevokt326
    @evoktevokt326 5 ปีที่แล้ว

    What does these lines of code mean exactly?
    if(typeof callBack === 'function') {
    callBack(data[counter]);
    }
    I suppose it checks if the argument callBack is a function, and if it is, what callBack(data[counter]); means?
    And why when calling the processStudents function we feed it as arguments the students array (which I understand) and a function that takes as a parameter an object. What's the object in this case, I'm confused. How does JS know that obj refers to each element of the array students?

    • @AllThingsJavaScript
      @AllThingsJavaScript  5 ปีที่แล้ว

      That if statement simply checks and makes sure that callBack is a function before we invoke it.

  • @drj9403
    @drj9403 4 ปีที่แล้ว

    at last I understood callbacks 👍

  • @saehoondannykim9469
    @saehoondannykim9469 4 ปีที่แล้ว

    Great Lecture!
    I got a question.
    Assume that I only add the total number of student from east.
    I have the code:
    function countEastStudent() {
    var count = 0;
    processStudent(student, function(east) {
    count++;
    });
    console.log(count);
    }
    countEastStudent();
    Is there any better way to add it?
    Thanks.

    • @AllThingsJavaScript
      @AllThingsJavaScript  4 ปีที่แล้ว

      You would need to check and make sure the student is from east. So put count++ inside an if statement: if (east.school.toLowerCase() === 'east') { count++ } Though I haven't tried it I think that would work for you. Remember that the parameter east is receiving an object from the array. So you need to check the school property of that object.

  • @Martin958
    @Martin958 4 ปีที่แล้ว

    How does the function know it has to iterate through the array 'students'?
    Also how does it define the variable 'data' as being relevant to the array?

    • @livinfenaya9915
      @livinfenaya9915 4 ปีที่แล้ว +1

      while defining the function processStudents we have two arguments (data,callback)
      while calling the function processStudents we call by(students,a function that uses the callback value)
      hope you undestand :)

  • @IkeSpeaksUp
    @IkeSpeaksUp 4 ปีที่แล้ว

    Soo good! Thank you for the help!

  • @kornelijekovac9793
    @kornelijekovac9793 3 ปีที่แล้ว

    4:20 Wasn't there a normal way to do this? Something like:
    logWithDelay(){
    doNothing(3000);
    console.log("No callback or whatever");
    }
    Why was there a need to complicate the code with that?

    • @AllThingsJavaScript
      @AllThingsJavaScript  3 ปีที่แล้ว

      setTimeout requires a callback. There is no other way to use setTimeout.

  • @westonpetersring
    @westonpetersring 4 ปีที่แล้ว

    Why do you have ?
    if(typeof callback === callback).
    What is this line doing?

    • @AllThingsJavaScript
      @AllThingsJavaScript  4 ปีที่แล้ว +1

      typeof checks the type of a value. It should be typeof callback === 'Function' I check to make sure it is a function before I try to invoke it. If I try to invoke something that is not a function, it would produce an error.

  • @noysaban5585
    @noysaban5585 6 ปีที่แล้ว +3

    That's great! Thanks :)

  • @kunalbidkar6340
    @kunalbidkar6340 6 ปีที่แล้ว

    Hi... I am a newbie to the JS world. Awesome explanation. I just have one query. When you call the processStudents function and pass in the anonymous function which checks if the score is greater than 60. So what is the flow of the execution? How is it run through the entire array? Is it something like it first loops through the first element of array, checks whether it is east or west and then calls the callback function for that particular data index. The loop increments and again east is checked and then second time the callback logic is invoked? Thank you

    • @AllThingsJavaScript
      @AllThingsJavaScript  6 ปีที่แล้ว

      So the for loop goes through each element in the array one at a time. If the school for the element in the array equals east, then it invokes the callback. Once that is done it comes back to the next element in the array. Does that help?

  • @RickyRicheRebelle
    @RickyRicheRebelle 4 ปีที่แล้ว

    so... basically a callback is doing "function y(x){x()}; y(function(){});" or "let x = function(){}; function y(z){z()}; y(x);", instead of simply doing "function x(){}; function y(){this.x()}; y()" ? seems very... unnecessary o.0 setTimeOut is asnyc, ok i understand; but for me setOnSomethingListener is merely calling another function in a function, nothing async/back calling there o.0

    • @AllThingsJavaScript
      @AllThingsJavaScript  4 ปีที่แล้ว

      A callback doesn't have to be asynchronous, but you can't do asynchronous programming without callbacks. Therefore, central to effective JavaScript coding. Having said that callbacks also present a different pattern for coding, which is a lot of what you see in this video.

  • @abdelrahman2348
    @abdelrahman2348 6 ปีที่แล้ว

    great very great explanation ,will you make a tutorial for node.js ??

    • @AllThingsJavaScript
      @AllThingsJavaScript  6 ปีที่แล้ว

      node is on my list, but it will probably come a bit later. Thanks for the feedback!

    • @abdelrahman2348
      @abdelrahman2348 6 ปีที่แล้ว

      All Things JavaScript, LLC thabks for your attention I appreciate that but i have something in nodejs that I couldn’t understand can i ask you please about it ,it’s all about 7 lines of codes

    • @AllThingsJavaScript
      @AllThingsJavaScript  6 ปีที่แล้ว

      Post the code

  • @Gj1118
    @Gj1118 5 ปีที่แล้ว

    can you please let me know which "solarized light" color scheme you are using ? better still, can you please pass me a link ? - Much appreciated.

    • @AllThingsJavaScript
      @AllThingsJavaScript  5 ปีที่แล้ว

      Here are my settings. Hopefully that will help:
      {
      "color_scheme": "Packages/Solarized Color Scheme/Solarized (light).sublime-color-scheme",
      "font_size": 21,
      "ignored_packages":
      [
      "Vintage"
      ],
      "theme": "Default.sublime-theme",
      "translate_tabs_to_spaces": true,
      "word_wrap": true
      }

  • @akshay__sood
    @akshay__sood 4 ปีที่แล้ว

    Is there something sort of synchronous and asynchronous callback? If yes what's their difference?

    • @AllThingsJavaScript
      @AllThingsJavaScript  4 ปีที่แล้ว +1

      A synchronous callback does not take advantage of something like setTimeout (handled by the browser). Thereby a synchronous callback is simply invoked when the code reaches the and is ready to do the callback.

    • @akshay__sood
      @akshay__sood 4 ปีที่แล้ว

      @@AllThingsJavaScript
      Thank you for you reply.
      How can we identify or know or find out if a callback is synchronous or asynchronous?

    • @AllThingsJavaScript
      @AllThingsJavaScript  4 ปีที่แล้ว +1

      @@akshay__sood In order for something in JavaScript to truly be synchronous, it must take advantage of the outer environment; the browser in the case of a web page. JavaScript is single threaded so it can only process one thing at a time. By using something like setTimeout or fetch (handled by the browser) we achieve asynchronous code, but this kind of code requires a callback in order to integrate back to the JavaScript engine.

    • @akshay__sood
      @akshay__sood 4 ปีที่แล้ว

      @@AllThingsJavaScript so anything that happens after something (like set timeout or event handlers) is asynchronous ?
      With asynchronous code as you mentioned we need to go back to JD engine so that's why they are callback?

    • @AllThingsJavaScript
      @AllThingsJavaScript  4 ปีที่แล้ว

      @@akshay__sood setTimeout and event handlers allow asynchronous coding. A call back is any function that is "called back". Call backs are used with setTimeout etc. because it allows the function to be called back once the task, like setTimeout, is done.

  • @firstignitor
    @firstignitor 2 ปีที่แล้ว

    so smooth. ilke it

  • @yokanho
    @yokanho 5 ปีที่แล้ว

    Can someone explain why in processStudents function, he use "data" as the first argument? Wouldn't it be more convenient to use the variable "students"? (all "data" change to variable "students").
    Also since when does the obj has this score and name property? => obj.score , obj.name . Am I missing something here?

    • @AllThingsJavaScript
      @AllThingsJavaScript  5 ปีที่แล้ว

      When you put a variable in a function it is defined for that function and can accept any data passed into it. So if I put students that would be find, but I would still need to pass in the data from the stundents variable. Does that make sense? The callback is a function that gets invoked. It has a parameter obj, which is just a variable. That variable receives an object and that is why I refer to obj.score and obj.name. I hope that helps.

  • @80Vikram
    @80Vikram 5 ปีที่แล้ว

    11:12, can you explain a bit in detail, it's getting confusing at this point. Is this another way of using callback function ?

    • @AllThingsJavaScript
      @AllThingsJavaScript  5 ปีที่แล้ว

      Basically, the callback is being defined from the function keyword to the closing curly brace. This is the function being passed into the callback parameter. This is the callback function. Does that help? If not could you specify what part is confusing?

  • @parvezmd6455
    @parvezmd6455 6 ปีที่แล้ว

    //array is here
    processtudent function(some,callback)
    {
    //console.log("1st call");//it is printed once my doubt
    //loop through array element
    if(cond)
    callback(arrayelement)
    }
    process trident(array is passed,function(arrayelement recieved)
    {
    if(cond)
    }
    //my Question
    processtudent function is called then one console is printed,callback is executed how 2nd time callback function is executed??(why console("1st call")is executed once?

    • @AllThingsJavaScript
      @AllThingsJavaScript  6 ปีที่แล้ว

      I think it would help to see the contents fo the array. Can you post the entire code?