Because the DOMContentLoaded event fires after the HTML has been read. The load event waits for the CSS, JavaScript, images, fonts, media, etc. The time delay for the load event can be much greater than DOMContentLoaded.
passing in resolve in to a setTimeout .. is resolve itself a function? normally i see setTimeout(function() ..... Also, your catch, you wrote console. error, should it have been console.log(err) ? or perhaps console.error(err) .. Thank you
Resolve is a function so it can be passed to the setTimeout as the function to call. Console has many methods. Error warn info log and more. The catch method expects a function. So console.error is the function being passed in.
Callbacks are the same regardless of what kinds of function you are calling. It doesn't matter if they are synchronous or asynchronous. The purpose of a callback function is to be called after the current function is complete. Since they don't return to the current function when they are done it doesn't matter if they are async. function start( theCallBackFunc ){ //do a bunch of things //then call the callback when complete theCallBackFunc( ); }
The dark forces of callback function brought chaos over the lines of resistance code. Then the Jedi Master Steve Griffith come with Promises and the Light won over darkness
Thank you again and again greetings from Bulgaria. Please help me once more Master Griffith to understand something that looks so trivial but yet eludes me. Please explain why you (and many other authors / developers) use anonymous intermediate functions to call the callbacks. Well, your example is a bit different but I hope you understand what I mean in general. someAsyncFn(() => { - here those functions I mean nextAsyncFn(() => { - here those functions I mean ............ What about using them directly. Like: someAsyncFn( nextAsyncFn( ............ I have seen examples of those too. So what is the difference ? Thank you.
Using this example from my code: delay(delay1) .then(() => changeBtnColor()) //return value gets passed to the next then() .then((d) => delay(d)) It could also be written like this: delay(delay1) .then( changeBtnColor ) //return value gets passed to the next then() .then( delay ) Both do the exact same thing. Normally I would add the extra anonymous function if there were a couple of lines of code to add. In this example, it was just to keep the appearance consistent and it is easier for junior devs to understand.
@@SteveGriffith-Prof3ssorSt3v3 Once again the Jedi Master Steve Griffith came to the rescue to one of his students as he was surrounded by dark and DECEIVING forces of JavaScript. For more info where the story began - look for IoannisX down below . This one sentence was the key. "Normally I would add the extra anonymous function if there were a couple of lines of code to add." Thank you.
This channel is underrated. Has no click bates, fancy previews and the quality of the content is amazing. Thank you Steve!
completely agree!!!
true he is gem,I wanna share this channel on social media to support this man,and so that everyone get advantages
I fell in love with your voice! Also the video is very clean and helpful! Thank you!
This is just a spectacular channel! He explains complicated stuff in a very succinct and professional manner.
Thank you for the clear and concise video. This deserves more views
This is explained so well, thank you very much
Next : convert your promises to async-await
Love your channel
Very useful information
Thank you very much. In the then() chaining we could add an optional function for reject correct?
Sure
very nice explaination..
Why do you use the 'DOMContentLoaded' event rather than the 'load' event?
As always, thanks for the video, Steve!
Because the DOMContentLoaded event fires after the HTML has been read. The load event waits for the CSS, JavaScript, images, fonts, media, etc. The time delay for the load event can be much greater than DOMContentLoaded.
@@SteveGriffith-Prof3ssorSt3v3 aah okay. Thank you!
Sir, please give a video about Node JS Async Hooks Module.
Please add any tutorial requests in the comments here - ua-cam.com/video/LCezax2uN3c/v-deo.html. - and vote for others that you like.
passing in resolve in to a setTimeout .. is resolve itself a function? normally i see setTimeout(function() .....
Also, your catch, you wrote console. error, should it have been console.log(err) ? or perhaps console.error(err) .. Thank you
Resolve is a function so it can be passed to the setTimeout as the function to call.
Console has many methods. Error warn info log and more. The catch method expects a function. So console.error is the function being passed in.
Can you explain callback to async function
Callbacks are the same regardless of what kinds of function you are calling. It doesn't matter if they are synchronous or asynchronous. The purpose of a callback function is to be called after the current function is complete. Since they don't return to the current function when they are done it doesn't matter if they are async.
function start( theCallBackFunc ){
//do a bunch of things
//then call the callback when complete
theCallBackFunc( );
}
The dark forces of callback function brought chaos over the lines of resistance code. Then the Jedi Master Steve Griffith come with Promises and the Light won over darkness
good content!
Thank you again and again greetings from Bulgaria.
Please help me once more Master Griffith to understand something that looks so trivial but yet eludes me. Please explain why you (and many other authors / developers) use anonymous intermediate functions to call the callbacks. Well, your example is a bit different but I hope you understand what I mean in general.
someAsyncFn(() => { - here those functions I mean
nextAsyncFn(() => { - here those functions I mean
............
What about using them directly. Like:
someAsyncFn(
nextAsyncFn(
............
I have seen examples of those too. So what is the difference ?
Thank you.
Using this example from my code:
delay(delay1)
.then(() => changeBtnColor()) //return value gets passed to the next then()
.then((d) => delay(d))
It could also be written like this:
delay(delay1)
.then( changeBtnColor ) //return value gets passed to the next then()
.then( delay )
Both do the exact same thing. Normally I would add the extra anonymous function if there were a couple of lines of code to add. In this example, it was just to keep the appearance consistent and it is easier for junior devs to understand.
@@SteveGriffith-Prof3ssorSt3v3 Once again the Jedi Master Steve Griffith came to the rescue to one of his students as he was surrounded by dark and DECEIVING forces of JavaScript. For more info where the story began - look for IoannisX down below .
This one sentence was the key.
"Normally I would add the extra anonymous function if there were a couple of lines of code to add."
Thank you.
❄