Understanding JavaScript Callbacks

แชร์
ฝัง
  • เผยแพร่เมื่อ 23 ธ.ค. 2024

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

  • @ayasswain
    @ayasswain 5 ปีที่แล้ว +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.

  • @Foody-j4z
    @Foody-j4z 2 ปีที่แล้ว

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

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

    Your voice is Crystal clear...

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

      but his keyboard sounds crappy :)

  • @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.

  • @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.

  • @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

  • @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!!!!

  • @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

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

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

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

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

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

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

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

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

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

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

  • @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

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

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

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

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

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

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

  • @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.

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

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

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

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

  • @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.

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

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

  • @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

  • @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.

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

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

  • @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.

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

    pure and simple explanation

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

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

  • @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!

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

    Your explanations are very concise.

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

    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  3 ปีที่แล้ว

      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.

  • @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.

  • @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

  • @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.. :)

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

    best explanation on call backs thanks

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

    Awesome your teaching is very logic and simplified !!

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

    Excellent Explanation thank you

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

    This is so slick - I love it

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

    Great explaination.

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

    at 15:00 min ok if determineTotal (line 26 ) is a seperate function and parameter students (line 30 ) which is the entire array is passed in, how come the total count is 5 instead of 7 ? Thanks for any explanation

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

      Because in the processStudents function we have a conditional that filters students that belong to East and there are 5 of those. Does that help?

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

      @@AllThingsJavaScript ok its the processStudents function in line 10. I`m slowly getting there. Thanks

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

    Very clearly explained. Thanks!

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

    Very clearly explained

  • @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?

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

    this is very good tutorial for everyone .Thanks a lot

  • @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

  • @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.

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

    Great tutorial on JavaScript callback functions. Well done!

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

    This is a really good tutorial!

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

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

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

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

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

    Great job explaining this topic 👍🏽 thanks!

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

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

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

    Thanks... Finally i understand by this explanation ❤

  • @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.

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

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

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

    The best callback ever

  • @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 :)

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

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

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

    what a great explination. Thank you.

  • @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.

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

    10:03 where is the definition of callback function ? Isn't it should be defined before calling it ?

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

      The function is being defined at the same time it is being passed in. This is called an anonymous function and happens quite frequently in JavaScript. Notice that the second parameter starts with function; this is where I am defining it.

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

    Thank you so much, I really got the concept

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

    You are a legend man!

  • @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!

  • @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.

  • @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 5 ปีที่แล้ว

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

  • @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.

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

    Awesome explanation, thank you!

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

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

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

    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  6 ปีที่แล้ว

      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.

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

    Thank you so much; very useful!

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

    Thanks All concepts are clear now

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

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

    • @AllThingsJavaScript
      @AllThingsJavaScript  5 ปีที่แล้ว +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.

  • @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

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

    There is a way to get the code along for checking or for boilerplate ?

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

      I haven't put together a way to make this possible yet.

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

      All my courses provide code for the examples and exercises.

  • @Eevee13-xo
    @Eevee13-xo 5 ปีที่แล้ว

    How would I filter images on a page using a search bar or drop-down. Could I use data-*?

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

      You could also use queryselectorall. Have you tried that. I have a few tutorials on it.

    • @Eevee13-xo
      @Eevee13-xo 5 ปีที่แล้ว

      @@AllThingsJavaScript I haven't! I'll check it out when im home from work! Also I'm amazed at the quality of content!

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

    Great tut. Subscribed

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

    Brilliantly explained! Thanks a ton!

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

    Great video. Clear and understandable.

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

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

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

    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  7 ปีที่แล้ว

      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?

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

    Could you please make tutorial of promise in javascript?

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

      I will add that to the list.

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

      thanku so much ,eagerly waiting

    • @codeordie-uw1il
      @codeordie-uw1il 6 ปีที่แล้ว +2

      Its funny he promised to make a promise video.

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

    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  6 ปีที่แล้ว

      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
      }

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

    Thanks, clearly explained

  • @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.

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

    Really Helpful

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

    Ur amazing teacher sir

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

    Very well done

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

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

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

    Hi thanks for the tutorial. I have a doubt, please clarify it. We are creating a processStudents function which accepts callbacks. Why can't we create a function called processEastStudents which returns object of only students from east and then call that function in other functions like determineTotal instead of using callback functions. Can I know what are the drawbacks of that implementation? Thanks

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

      With the simple example I provided, the solution you suggest might work just fine. But remember, the advantage of callbacks is the flexibility. The function we pass in could be any function. When you create a processEastStudents function, that function can only be used for one purpose.
      Also, keep in mind that JavaScript is very flexible. There is very seldom only one way to do things. In JavaScript you need to understand what is possible so you can choose between alternatives. And some alternatives are better. One of the advantages of callbacks is flexibility, but probably the biggest advantage is asynchronous coding.

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

    really u r great explainer.....

  • @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?

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

    Do you have any video related with indexeddb?

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

      th-cam.com/video/g4U5WRzHitM/w-d-xo.html Also, you can get a complete list of tutorials here: www.allthingsjavascript.com/youtube.html