Explained simply, covered the practical uses and applications of a Callback Function and broke the subject down and showed variations and the evolution of named, anonymous and arrow functions. You've helped me an incredible amount with just this video. Not often I comment but thank you!
But you didn’t show callback example with initially created functions like taskOne, taskTwo where where taskTwo has to be executed only after taskOne is completed ???
I was thinking the same. My working code is following: const task1 = function(callbackTask2) { return function(){ console.log('task1'); callbackTask2(); } }; const task2 = function() { console.log('task2') }; setTimeout(task1(task2), 10000);
@@DennisSmdFreefightTrainer An easier write would be Function task1(callback){ Alert('task one') Callback() } Function task2(message){ Alert(message) } Settimeout(()=> task1(task2('i was called'))
Great. Makes sense, but why does the function need to include the callback parameter in the first place? Why can’t it just be called directly inside the other function?
Is this correct? (1) callback functions can assure functions will be executed in a certain order (2) callback functions can be used to attach event listeners to buttons and other various HTML objects
Thanks for the video, after reading your FCC article; I've below doubts kindly clarify Q 1. In example "function print(callback) { callback(); }" >> Is "callback" is keyword ? Q 2. One more example from MDN function greeting(name) { alert('Hello ' + name); } function processUserInput(callback) { var name = prompt('Please enter your name.'); callback(name); } processUserInput(greeting); >> why can't I use the string "greeting" instead of "callback" in "processUserInput" function ?
Q1: Callback is not a keyword. Q2: Because "callback" is a parameter for the function processUserInput, like the "name" is a parameter too (for the greeting function). Later in this code, the greeting function is being passed as a function argument (in the last line), and it will replace the "callback" parameter. I hope my answer helps...
At 2:27 min , how does javascript execute task 2 before task 1. Since , as you said javascript is sequential shouldnt task one be executed then delayed for 2 seconds and then task two be executed? Thanks for help.
I believe that the best way for learning is coding by yourself rather than watching someone else's live coding. But you can check other youtube channels like traversy media, dev ed and more.
thank you, i can suggest that you can buy an online tutorial course from udemy or something like that, rather than a book, because you can view it live on a project and code simultaneously :)
can u please tell me why foreach loop I defined a callback but the thing is it taking the parameters for callback function is fixed in js k=[1,2,3,4,5,6,7,8] i=1 k.forEach((element,i) => { if(element===i){ console.log("TRUE") } }); it is giving me false false false false false false false then when i removed i as parameter then it is working fine like this k=[1,2,3,4,5,6,7,8] i=1 k.forEach((element) => { if(element===i){ console.log("TRUE") } }); output= TRUE
Hello. Can you help me with one example. Here we are the code. function print_some(name, callback){ let a = 10 + 30; callback(a); } print_some("James", a => { alert(a+9); }); I can't understand how it works. How function know about variable a. And why when I use another name for arrow function it doesn't work. I will so apriciate for the explanation.
This is really frustrating, You showed an example of oneTask and second Task told us how we can run secondTask after the wait but didn't even show the example.
I'm sorry man, but you are using a different example! In the first case, you have 2 functions - 1 and 2. You want to run one of them after 3 secons, and then run the second one. You just showed how to delay a function, man.... you only taught how to delay the first function just like you did at the first time. Where's the second function?
Hi Victor, thank you for the question. That's right, I used different examples. The first case is showing that, functions can be delayed because of any issue (late response from server, slow internet etc.) , and since I can't simulate it (because we don't have a real server, it's just my local), we have to use a setTimeOut function. But even if there is a delay, we want to run the second function after the first one. OK? So, to prevent running the second function before the first one, what we need to do? We need to use a callback. In the second example. I'm exactly showing how to use a callback function. You're asking where the second function is. What is the function inside the setTimeout function?
Hi, I don't understand how to run a second function (different from setTimeout) affter the first function executed? lets say there are two function same as the first example (when the first function is delayed), and I want that the second function will be executed after the first (delayed) function is executed, how it can be done? Thanks a lot!
Hi, I don't understand how to run a second function (different from setTimeout) affter the first function executed? lets say there are two function same as the first example (when the first function is delayed), and I want that the second function will be executed after the first (delayed) function is executed, how can this be done? Thanks a lot!
Hi, in your case, you need to pass the second function to the first one, so which means that the second function cannot be passed and executed before the first function is executed. It has to wait for the first one. I hope this helps to answer your question.
Abi Ingilizcen guzel, anlatiminda sade ve guzel, ogretmen gibi, udemy'e JS anlatan bir kurs yap istersen? Kanalini tesadufen buldum, Rob Merrill isimli kisini udemy'de kursunu bakiyordum, adam habire call back function diyordu, anlamak icin senin makalen geldi ordanda vidyonu buldum.
Cok tesekkürler :) Kurs cekmek uzun süren bir is, belki aylar sürer, ama takipcim cok artarsa o zaman olur, yil sonuna dogru bire bir, ya da 2-3er kisilik özel ders de vermeyi planliyorum.
Bütün dünyadan takipciler oldugu icin sadece ingilizce video yapabiliyoruz. Web yazilimi anlatan cok güzel türkce kanallar da var, onlari takip edebilirsin.
Explained simply, covered the practical uses and applications of a Callback Function and broke the subject down and showed variations and the evolution of named, anonymous and arrow functions. You've helped me an incredible amount with just this video. Not often I comment but thank you!
But you didn’t show callback example with initially created functions like taskOne, taskTwo where where taskTwo has to be executed only after taskOne is completed ???
I was thinking the same. My working code is following:
const task1 = function(callbackTask2) {
return function(){
console.log('task1');
callbackTask2();
}
};
const task2 = function() {
console.log('task2')
};
setTimeout(task1(task2), 10000);
@@DennisSmdFreefightTrainer
An easier write would be
Function task1(callback){
Alert('task one')
Callback()
}
Function task2(message){
Alert(message)
}
Settimeout(()=> task1(task2('i was called'))
Emeğiniz için teşekkürler, anlaşılması basit ve açıklayıcı bir şekilde sunmuşsunuz...
PERFECT EXPLANATION STRAIGHT TO THE POINT
This is the kind of explanation I like.
a very nice couple of examples. thank you!
Cheers, Cem!!
You made it so simple to understand. Great explanation! Thanks
Thank you mate, you have just helped me to understand the concept perfectly
Great stuff! exactly what I was looking for. Thank you!
You're welcome :)
You did not give the solution to your 1st example. On How to run the task 1 before task 2
This video just gave me the explanation I needed, thanks alot
thanks, very helpful!
Thank you for your clear explanation.
thank you for explanation in a simpler way
Well explained, thank you!
Great video. Easily Explained. Thanks.
This was the easiest way u taught..Thank u so much..!
Just wanna ask u what's the difference between call back & high order function
Thank you :) I don't know either, sorry.
HOF and Callbacks both are same. :)
Great. Makes sense, but why does the function need to include the callback parameter in the first place? Why can’t it just be called directly inside the other function?
Easiest and the best explanation!🙌🏻
best way to explain it awesome !!!
Thank you , it was awesome ;
that was soooo clear
Great tutorial man .
Thank you very much for this video :) It was helpful for me!
well explained thanks!
Is this correct?
(1) callback functions can assure functions will be executed in a certain order
(2) callback functions can be used to attach event listeners to buttons and other various HTML objects
Yes, both of them are correct.
@@cemeygimedia thank you for your lecture and answer. You're a great teacher!
You're welcome Jeffrey! Consider subscribing for new videos :)
Eyw usda güzel anlattınız
Thank you, I like your Explanation
Thank you, great and clear example :)
Very easy to understand. Thank you, Cem!
You're welcome :)
Great explanation! Thank you!
Excellent explanation!
Thank you :)
great job
very helpful
Thanks for the video, after reading your FCC article; I've below doubts kindly clarify
Q 1. In example "function print(callback) {
callback();
}"
>> Is "callback" is keyword ?
Q 2. One more example from MDN
function greeting(name) {
alert('Hello ' + name);
}
function processUserInput(callback) {
var name = prompt('Please enter your name.');
callback(name);
}
processUserInput(greeting);
>> why can't I use the string "greeting" instead of "callback" in "processUserInput" function ?
Q1: Callback is not a keyword.
Q2: Because "callback" is a parameter for the function processUserInput, like the "name" is a parameter too (for the greeting function). Later in this code, the greeting function is being passed as a function argument (in the last line), and it will replace the "callback" parameter. I hope my answer helps...
@@cemeygimedia TAZ for detailed and simple clarification. Callback is always confusing for the first time
At 2:27 min , how does javascript execute task 2 before task 1. Since , as you said javascript is sequential shouldnt task one be executed then delayed for 2 seconds and then task two be executed? Thanks for help.
Is callback function prevent asynchronous?
Herseyi niye bu kadar iyi anladim diyordum ki farkettim ki Türkmüşsün.
Nicely explained.
Thanks,.
One question: what is window.unload and why did you have to use that?
Its been 6 months since this question was asked, but if you got the answer i would love to know
Thank you.
Well Explained! can you give some more examples on callback function (real-life application examples) thx.
We need answers to this plssss
I am learning web development and done with HTML, CSS and JS, can you please suggest good live coding tutorial to sharpen these skills ?
I believe that the best way for learning is coding by yourself rather than watching someone else's live coding. But you can check other youtube channels like traversy media, dev ed and more.
Ur explanation is amazing bro plz tell best book for JavaScript and css and html plz
thank you, i can suggest that you can buy an online tutorial course from udemy or something like that, rather than a book, because you can view it live on a project and code simultaneously :)
@@cemeygimedia thank u sir ♥️
@@cemeygimedia but tutorial for beginners and not use that much
can u please tell me why foreach loop I defined a callback but the thing is it taking the parameters for callback function is fixed in js
k=[1,2,3,4,5,6,7,8]
i=1
k.forEach((element,i) => {
if(element===i){
console.log("TRUE")
}
});
it is giving me false false false false false false false
then when i removed i as parameter then it is working fine like this
k=[1,2,3,4,5,6,7,8]
i=1
k.forEach((element) => {
if(element===i){
console.log("TRUE")
}
});
output= TRUE
great tutorial man
Hello. Can you help me with one example. Here we are the code.
function print_some(name, callback){
let a = 10 + 30;
callback(a);
}
print_some("James", a => { alert(a+9); });
I can't understand how it works. How function know about variable a. And why when I use another name for arrow function it doesn't work. I will so apriciate for the explanation.
This is really frustrating, You showed an example of oneTask and second Task told us how we can run secondTask after the wait but didn't even show the example.
I love your voice :D
great explanation!!!!
speed 1.25x
Thank you so much my friend
really cool, thanks!
Well done Cem!
Thank you!
you need to add your js script at the end of the body i think thats why it didn't work first time
I'm sorry man, but you are using a different example! In the first case, you have 2 functions - 1 and 2. You want to run one of them after 3 secons, and then run the second one. You just showed how to delay a function, man.... you only taught how to delay the first function just like you did at the first time. Where's the second function?
Hi Victor, thank you for the question. That's right, I used different examples. The first case is showing that, functions can be delayed because of any issue (late response from server, slow internet etc.) , and since I can't simulate it (because we don't have a real server, it's just my local), we have to use a setTimeOut function. But even if there is a delay, we want to run the second function after the first one. OK?
So, to prevent running the second function before the first one, what we need to do? We need to use a callback. In the second example. I'm exactly showing how to use a callback function. You're asking where the second function is. What is the function inside the setTimeout function?
Hi, I don't understand how to run a second function (different from setTimeout) affter the first function executed?
lets say there are two function same as the first example (when the first function is delayed), and I want that the second function will be executed after the first (delayed) function is executed, how it can be done?
Thanks a lot!
function name(){ return console.log('name')}
function next(){ name(); return console.log('next')}
next()
thanks man
Great
Eyvallah Cem abi freeCodeCamp de buldum.
simple and useful
thanks a lot
Still don't get it. You seemed to rush it too much.
Hi, I don't understand how to run a second function (different from setTimeout) affter the first function executed?
lets say there are two function same as the first example (when the first function is delayed), and I want that the second function will be executed after the first (delayed) function is executed, how can this be done?
Thanks a lot!
Hi, in your case, you need to pass the second function to the first one, so which means that the second function cannot be passed and executed before the first function is executed. It has to wait for the first one. I hope this helps to answer your question.
@@cemeygimedia Thank you. It really helped
!
@@טלחדד-נ9ו i don't know what he means, does it mean like this taskOne(taskTwo)
Thanks for the amazing explanation! How did you run this example in the browser?
Thank you, it is the live-server extension of VS Code. If you install it, you can run automatically in the browser
Great explanation!
Supppppperrrrrrrrrrrrrrrrrrrr
good explanation!
Thanks🙏
thanks u, you're so good
I came back 10 months after not understanding this video. I still don't get it. I'm screwed.
Thank you so much!:)))
i am is in new york where are u cem?
Nice :) I’m in Germany
thanks
wow, you are so amazing!
Abi Ingilizcen guzel, anlatiminda sade ve guzel, ogretmen gibi, udemy'e JS anlatan bir kurs yap istersen? Kanalini tesadufen buldum, Rob Merrill isimli kisini udemy'de kursunu bakiyordum, adam habire call back function diyordu, anlamak icin senin makalen geldi ordanda vidyonu buldum.
Cok tesekkürler :) Kurs cekmek uzun süren bir is, belki aylar sürer, ama takipcim cok artarsa o zaman olur, yil sonuna dogru bire bir, ya da 2-3er kisilik özel ders de vermeyi planliyorum.
The task example: function task1(callBack) {
setTimeout(() => {
console.log("task1");
}, 2000);
callBack();
}
function task2() {
console.log("task2");
}
task1(task2);
Abi Türkçe videolar da gelir mi ?
Bütün dünyadan takipciler oldugu icin sadece ingilizce video yapabiliyoruz. Web yazilimi anlatan cok güzel türkce kanallar da var, onlari takip edebilirsin.
Bu sıcak aksanı nerde duysam tanıtım. :)
The name "callback" does not make sense to me wish it was called something else.
confusing not helpful my guy
You could do better at explaining, cut out the unnecessary talk, simplify and re-release a new video
horrible, not helpful
Please reply..🙏
Thank you for nothing