javascript callback functions tutorial
ฝัง
- เผยแพร่เมื่อ 6 ก.ย. 2024
- fundamentals of Callback function in javascript explained
- How to pass functions as parameters.
- understanding callback hell
- use of callback functions
#JavaScript #Callback #function
*My Udemy Courses
www.udemy.com/...
www.udemy.com/...
Follow me for technology updates
* / techsith
* / techsith
* / techsith1
* / 13677140
* / patelhemil
Help me translate this video.
* www.youtube.co...
Note: use translate.goog... to translate this video to your language. Let me know once you do that so i can give you credit. Thank you in advance.
Thank you for explaining the "Why we use it". This often isn't explained and it definitely helps with understanding. Well done!
Thanks so much for this.
Currently learning Javascript on Codecademy and was hell of confused at the "HIGHER-ORDER FUNCTIONS
, Functions as Parameters" section, but this clarified everything. I'm so grateful.
I've previously favoured interactive learning of CodeCademy and FreeCodeCamp, but you've made me now look at video tutorials in a new light
This is exactly what I needed to understand how callbacks work. I'm doing a node tutorial that has anonymous callbacks defined in-line and i had no idea why you would go out of your way to make a function more complicated by writing a function around it. This clears it up SO much
Thank you, thank you, thank you.....I thought i'd never understand "callback" function, I've watched a few videos on this subject and could not grasp it and nearly gave up........but now......Thank you again.
Thanks for watching!
This is the best description of callback functions I've seen in all the internet. ...and believe me I've searched far and wide. Thanks for breaking this down for us!
Great example of callback, your calc function and callback really shows the reason for using callbacks.
This is the first video anyone and everyone should watch on this.
So many videos go SO deep and complex without covering the basics that its almost impossible to learn.
But you my friend.
Are the best.
Thanks Rick for the nice comment
I love the way you correct the syntax errors but leave the word back spelled incorrectly. That's a true programmer haha
Most valuable 15 mins of my day. Thanks! (y)
I have been trying to understand callbacks all day on various blogs and other videos and this is the first time it is making a lot of sense. Great video and explanation.
Glad you got it. Thanks for watching
after 3 hrs tried to figure out callback function, I found this video and help me understand how and why to use callback. thank you Sir.
The only one to come up with a simple and straightforward example of callback functions. Thanks!
Making it straight to the point. No BS.
Now I'm confident in using callbacks eventually forever. Thank you.
Thanks for watching Sridhar. I am glad that you will remember this forever, my job is done here. :)
“just in case somebody pass a garbage”
😂😂😂
:)
@@Techsithtube hhhh you are funny as hell you and i really enjoy your tutorials
let garbage = function(trash) => {...};
my favorite statement in the video
Whenever I'm about to watch your video I know that by the end of it I'll understand the concept I couldn't wrap my head around.
Thank you, kind sir!
PS. Thanks for taking time to brush up on your accent. Normally it's quite difficult to understand everything when the speaker has a strong accent. Have a nice day, kind sir!
Excellent point man (y)
The way you introduced callback satisfies the Open&Close principle in SOLID.
The O stands for: Open for extensions but close for modification. We are able to extend function "calc" as much as we want, but should not modify it ;)
Love your tutorial!!!
Excellent point. Thanks for sharing! :)
You actually teach these concepts very well. My bootcamp does a horrible job of explaining these functional programming concepts.
I am studying a course in JavaScript and they explained (call back function) but I was so confused after I was done, they made it seem so hard. Thank you for explaining, great JOB.
Best explanation I have found yet. You made callbacks very simple to understand. Thanks!
Sorting example was just awesome...I am almost following your channel for more than a year and get the job also as a node is developer...all credit goes to you 😄....now planning to learn data structures and algorithms... could you please help where I can start using JavaScript... because most of the examples are in Java or other languages...I want to do it practically.... thanks again I am earning bread for my family because of your channel :)
I have started a new channel for data structures and interview related questions. It's interviewnest feel free to check it out
Thank you so much! I learn a lot. I see that you are not uploading videos, you must return and teach the next generation. You are a great teacher!
I liked the point when u say y we r doing this. Many channels wont explain it. But the most imp point is y we r using a particular technique
Thanks for watching Rahul. I am glad that you learn something! :)
Amazing, I had 3 hours of this on my class yesterday, couldn't understand a thing! Cristal clear after 15 mins of your tutorial, thanks a lot!
You are teaching many valueable javascript lessons in a easy way. Your free service is highly appreciated. We were really dummies before we look at your lessons.
Thank you! Do let me know if you want certain topics covered.
Recently interviewers have asked stunning questions which I didn't expect.
1) How do u handle cache
2) How do u handle offline when DB disconnected, still my application should survive with offline data downloaded previously, once DB is connected then it should handshake and continue as normal
3) Handling Threads in Javascript when server need more time to process and send results to the client
4) minification of js. Is it so important? Usually ignore that
5) Versioning management in javascript. Is it so important? Usually ignore that
6) Unit testing in javasciprt
Other than these broadly lot of client side frameworks need to learn. (AngularJS, Backbone JS, Ember JS, Node JS, Require JS, Polymer, Handlebar, etc).
All the really good topics.
1) Handling cache
You can do something like this in your html
scr="myJs.js?121212"
basically add a new number every time your deploy. There is a good solution using gulp . I will create a tutorial on that.
2) How to handle offline ( there are multiple solution to this. If you are using a JS platform you can use their technique. for exmaple if you are using ember.js you can use ember data. I will have to create a tutorial on that.
3) for handling the Threads in Javascript ( I have a tutorial on that th-cam.com/video/pMK-jcOAYI8/w-d-xo.html)
4) minification.js it is important depending on your application and number of users. Tell me the size of your application and number of people involved. there is a gulp solution which is very easy to implement)
5) Which versioning management are you referring to ?
6) Unit testing is very important, however this again depends on the size of your application . If you are using a javascript platform, versioning comes with it so you can use it there . I will make a tutorial on that.
I am going to start Angular2 and EmberJs tutorials really soon. Angular2 is the latest platform and a very important one. EmberJs would cover handlebar as well. I am also thinking about polymer. If you are learning a new platform i would suggest that dont learn AngularJs1( this was the first version and going away soon) and Backbone.
3) Unfortunately JavaScript is single threaded. even using WebWorker is not multi threaded. This might change in the future.
4) Use npm and bower to solve the version issue. if client modifys the code and mixes dependancy. this would become their issue. You should be clear on how to install and if they are going to mix , they should let you know in advanceed.
6) Backbone is still used but not many people choosing it for new apps. I think if you have a simple project you can still use it .
Have spent days trying to understand the "callback", finally got it after watching your video. A huge, huge thank!
For a short video, it was actually quite full of informations.
Clear and concise so i appreciated it.
I watched it in 1.5 speed but it looked like it was at normal speed, so it's good, you obviously take the time to explain clearly and pronounce every word correctly. Thanks a lot for that because sometimes people talk really too fast or don't bother pronouncing anything the right way and you end up losing a lot of informations!
Thumb up (y)
Glad it helped, I think its very important to understand callbacks in JavaScript, no one should move forward without properly understanding it. Thanks for watching .
one of the best explanations for callback function
Thanks for watching!
after roaming months on youtube finally i found this 😊
I am glad you found it. Thanks for watching Ravish!
Finally understood callback...after watching this video...thanks a Lot
I'm a java developer with 5 years of experience in the technology and peripheral frameworks. I've recently started to mug into JS as our new requirements are all transitioning into it. As you can understand it's a new territory and the all these functions acting weirdly is mind numbing for a java guy. Thanks so much, your video helped me so much in understanding the core need for callbacks. Please make one on promises.
Hi there! your videos are very easy to understand and are all briefly explained, thankyou for making these videos! also I think it would be useful for you to create videos talking about the classes, constructors, and extending them in es6 because they seem to be also something which is going to be helpful at times. :)
I am going to create a tutorial on classes next.
8:59 how I feel sometimes, when I'm misunderstanding something in javascript, but this tutorial is great!
:) thanks for watching!
You deserve a quieter place to live and thank you for the great content!
Jason , you noticed :) Since that video , i do have a semi private bit more quieter place. :)
Thank You , I ' am Understand callback function you are great
Glad to hear that Ragab.
Thank you! Good video. So callback is just a placeholder when I want to be able to pass a function in to another function, then it acts as the function itself once we inject it in to the other function where we can substitute callback "in our minds" with the name of the function we passed in the code logic. Yay! I think I got it now!
No
I completely don't understand the hype for anonymous functions. You save writing one word really (name of the function!) at the cost of making the code MUCH harder to read and understand (nesting into nesting into nesting into....).
it depends on the application . if its a onetime thing you can use anon function.
You explained "Why" we use them rather than just "How" (which is less significant). Thank you.
Most important he explained when exactly it is useful! Thanks
Extremely good teaching. Argument caught, no error thrown.
Thanks :)
been scratching my head trying to understand callbacks in java. thank you very much for such a nice relief!
Hey, thanks for this, it's a very easy to understand explanation, I appreciate it!
Out of all of the videos on youtube, it's this one that gave me the eureka moment. I was very familiar with using callback functions in this way: someVar.addEventListener('click', () => {callback}) but creating a callback as a parameter for another named function really threw me off. Reall well explained. Thanks dude!
The best explanation i have found so far. Really good thankyou so much!!!
Thanks for the explanation - very clearly explained.
I have question though - if you have a pattern like this:
if (a === 1){
return "Hello world 1";
}
else {
return "Hello world 2";
}
Why not just code:
if (a === 1){
return "Hello world 1";}
return "Hello world 2";
As the else is unnecessary due to the first return causing flow to break out if it evaluates as true so an else in not needed?
That also work. :)
Previous comment didn't show up!
Here goes nothing:
Thanks pal! Made that simple to understand for a beginner like me (unlike so many geeky explanations).
I am glad it helped. Thanks for watching!
my doubt might sound silly but well please try to explain. In sort method what that return 1 and return -1 mean??
Thanks, its really the best explanation for callback functions - i watched a few videos and didnt get it till yet
Thanks techsith! This definitely cleared up what it means to callback a function. Sir, You are AWESOME!
You are most welcome! When started learning JavaScript, callback function was so confusing. Once you know callbacks lot of thinks openup
Thanks for such an excellent video on callbacks. I've read a lot and been through a few videos trying to grasp callbacks and it hasn't clicked in my head until I came across your video.
My confusion got cleared, more detailed, Thanks very Much
thanks for watching! :)
your second example just made me realize callbacks are could be more. Keep it up
I've been struggling for many hours finally understand callbacks. Thanks sir.
You're a hero! Thanks for this great tutorial!
Really u have explained very simply & smart way that anyone can catch it clearly and easily. Great job. Carry on and good luck for the next tutorials ;)
NOT ANYONE , I am the type person that does not understand ABSTRACT information and then can be expected to apply it to a real world situation. I have no idea what he was talking about and I have watch SO MANY JS videos I cant even count them. I understand HTML, CSS, PHP, SQL but I have yet to see a JS video where they apply it in a real world scenario all of this abstract language means nothing to me. ALTHOUGH, I am happy for you that it all makes sense. I just wish I could find a video that would TEACH JS in actual usage and not in abstract techno information.
Great explanation!! I understood more through your explanations. But I think the doWhatever callback at 9:06 returned undefined due to double console.log.... I could be wrong...
i am learning JS just from your tutorial and and you explanation is good God bless you Thank you
thank you so much from Egypt your explanation method is amazing it's really fine thank you so much i really love you. but i get a little bit confused because i feel that your playlists are not arranged if you rearrange it this will be a great thing.
How to find what parameters needs to be passed for callback in case of a third party libraries function
For example in socket.io
io.on('connect',(socket)=>{
})
How do we know socket is the parameter here
The best video of callbacks I've ever seen
Thanks for watching!
just loved the explanation, thank you sir.
Devendra, thanks for the comment! Keep on learning!
it is good explanation. Sir I am new to javascript field so I would request to create video with example of callback vs promise vs observable. if you would do then it would be great help to who are new to javascript. Thanks
This was a simple and clear explanation! I finally understand callback functions. Thanks for making this!!
i have been following your tutorials from some time and really wanted say thank you for ths wonderful job. not all got the capability to make others understand in a simple and precise way. again thank you
You are really awesome. I just love the way you explain complex concepts.
Please add more examples, it makes more clearer on concepts, love your videos. Guruji :)
Awesome video full clarification about callback.
Thanks for watching Gautam!
What I'm trying to understand, is the word "callback" unique and protected in JS? IS it what enables this behaviour to call other variable functions as parameters. Or could I just as easily write bob() ?
best explaination of callback function
Thanks for sharing. Callbacks have been driving me up the wall.
I am glad that it cleared up the concept of callbacks. :)
So, it seems to be a way of creating abstractions?
Whereas in other languages, one would create an "abstract function" or "interface".
Does that sound right, or no?
Best explanation of callbacks ever
Thanks man! This tutorial made me understand callback functions. Great way to explain essence of this JavaScript part :)
I really like the way to teach stuff, its comprehensive and clear, thanks for taking time to make these videos.
Very clear in explanation. This is the first video I've watched from you but plan on watching a lot more!
Welcome Eric, let me know if you want me cover specific topic. Thanks for watching! :)
You're the best! I spent two nights trying to grasp this callback concept and ended up understanding little. You made my progress real. thick books aren't always good :(
I was hoping this would be about callbacks that are handled by the browser. Why are these called callbacks? I don't think they are called callbacks in other languages unless the function is call is deferred?
in the second example how did we assume the values of each val1 and val2 ? from where function understood to make up for both with 0 and 1 index
Thank you so much, you gave such a clear and easy to follow explanation of callback functions.
Door knock @ 2:07...Seems somebody at home is not happy ;)
Twitch Style, lol :P
yes i too heard that
she didnt understod callbacks
his wife heard "callback" and she said "who the fuck are you calling he, your side bitch?"
ааааа ! Спасибо пасоны , угарнул ! )))
автору респект, хорошее ввод в колбэк функции.
Good videos, Keep up the good job
this examples make more sense for me cuz usually an=m not that gd with callbacks bt now am more comfortable with it thank you man
Thanks heaps. Straight to the point, clear and easy to follow. Been struggling with the instructions given on codeacademy on this very topic. Thumbs up mate.
THanks for watching Julian!
dear,
great tutorial on callback. but can you help me to explain how sort method get invoked automatically when we did not even call it manually?
Best explanation I've come across! Thank you
finally someone explained callbacks! thanks!
Hi Sir First of all i need to thank you for such a nice video which is available free of cost in online, I am a fresher started learning Java script, Can you suggest me some good books and useful links from where i can expertise my JS skills
Dude. Never knew you can do that. Awesome. Keep it up. If no one likes it people like me would like it.👍🏼
Ramazan, I really appreciate the like , thank you!
just want to say it has been well delivered and well prepared.
Techsith tutorial javascript it is helping me a lot Thank.
Great example of callback. Thanks man! This tutorial made me understand callback functions. Finally
a well explained video about callback functions. It's hard to find nowadays.
I've really struggled to understand callback functions and I'm still not 100% but this video really helped! Thanks
Great video. Question: Why do you have to return the callback function?
Ur videos are really very useful but give us some live example for every topic means while developing a project how can we use these topic,I would be more helpful.
Thank you! Finally a well explained video about callback functions. It's hard to find nowadays.
good explanation of callbacks. thnks
I liked your video. You do a great job describing callback functions. It's crystal clear to me now what it is. In C# they are called delegates.
your video has made call backs so simple for me!!! Thanks in tonnes ..
I am glad that you learnt Prerna. Thanks for watching! :)
thank you for explaining in Easy way
Nice, simple and to the point. Thanks!
Callback is a function which is passed to another FUNCTION and it will be executed at SOME POINT when the FUNCTION 's execution has finished.
Why not just after the FUNCTION'S execution, but after some point? Because it depends on the execution stack, if it's empty ,callback will be executed immediately after FUNCTION's execution and there is no other task in message queue.
This is what makes callback non-blocking.
Take it this way, I have some code that needs to be executed . But before this code I have some other code which is time taking maybe API calls, some other processing that can take time. Okay, what is the problem? Problem is JavaScript is single threaded and it runs code in synchronous way.
We don't execute this piece of code immediately but we pass it to WEB API. What WEB API does it process the task in the background, making the API CALL, and attaches the callback as an event handler that will be executed when the process is finished.
What will happen then?
After the process finishes, it push the callback to the message queue. Where this callback waits to be executed once the execution stack is empty.
Who determines that ,EVENT LOOP. Once the execution stack is empty it will process the message queue.