I love learning from you so much. The biggest bummer to learning things about programming is people tend to over complicate things when they don't need to. I guess to sound super smart??? Every time I watch a video from you nothing is over complicated. It's stated just how it is. THANK YOU! Also thank you for teaching me about promises.
Hey Dan, just another quick tip to make your code slightly shorter. When you write .catch(err => console.error(err)) you can just write .catch(console.error) instead. This is the case every time you would call an arrow function with just one parameter, only to call another function on that parameter.
@Sph2329 do we need bind() here, I think the arrow syntax (even though not explicitly present) will take care of the context, so we need not fix "this" using bind IMHO.
Hi, you have a SetUp Function() then you have a NoCanvas Function.. Jusst curious! Does Javascript automatically create a canvas in the DOM? & if so/ or not... is NoCanvas a native JS function itself? or have you defined that elsewhere? Promises looking handy.
Noob question: at 3:41 you have delay() called on line 3, but defined on line 7. How does this work? I thought you had to define before calling. I could be mixed up too as I have limited experience. Got the code bug and trying to learn.
Jason Bahr Functions that are written like that are hoisted; it means that the program can run it, even though they are written somewhere else of where they are called. Every function notations have their pros and cons. Please correct me if I’m wrong. I’m still a noob too.
You should really cancel execution of the function after rejecting otherwise the program will be running the setTimeout to resolve a rejected promise which is a waste of system resources :)
Good to hear it's fixed in the next one, but yeah it's really good to get in the habit of always returning if you reject or resolve a promise as I believe calling any of those functions more than once can result in undefined behavior?
Cole Erickson depends on what it’s doing, but yea. The promise itself will be fine since it can only resolve or reject once but doing the action anyway could cause some problems elsewhere in some cases
anyone notice that the output from the resolve never got delayed? I applied this code inside a console and it delayed it by the time indicated, but the createP method displayed the message right away. edit: i figured out my issue. The setTmeout() has to have a callback argument as follows and then the delay works: if (isNaN(time)) reject(new Error(time + " is not a valid number")); else setTimeout(() => resolve("test resolved"), time);
No. It's just a callback passed to the Promise constructor. The name resolve and reject is just a convention, but you can name it anything, it doesn't really matter.
8:40 Yes, it works. But why. You didn't put an else block around setTimeout and you don't return after you call reject. So even if the isNaN function returns true it should still execute setTimeout. Does that mean the function which is passed to the Promise constructor automatically returns after the function passed in the second argument is called? If yes, I don't like that. That should be in the control of the developer.
It works because promises don't change after they settled (either fulfilled or rejected). So you cannot have a promise that will reject after 1 second, but then resolve after 2 second. In this implementation the setTimeout still happens, the resolve function will be called (after the delay), but it won't change the rejected promise into a fulfilled one.
Hello, why I need to use resolve() in my code. If not, then will never execute. I'm not sure it is related to angular. I have new Promise(resolve,reject). I expected that it will continue to execute and auto return resolve and if any error will return rejected
Hello, guys am a little bit confused tried running similar code in vanilla javascript while it works, the timing is completely off. the function runs immediately in the browser. delay(9000) .then(document.write('Promise is sucessful')) .catch(err => console.error(err)) function delay(time){ return new Promise((resolve,reject)=>{ setTimeout(resolve,time); }); }
Hi I encountered a similar issue, my resolve was returned immediately without delay. Then I read that it's because I wrote it as setTimeout(resolve(), time) . Note the parentheses. It should be setTimeout(resolve, time) . But I see that yours is written without parentheses, so it should run with delay though. That's strange.
I am the only one that is trying codes? @7:15 the code doesnt work, at least not for me. Where am i taking a mistake? Here is the code, maybe can someone tell me with just a look at it: function setup() { delay(1000) .then(() => createP('Hello')) .catch((err) => console.error(err)); } function delay(time) { return new Promise((resolve, reject) => { setTimeout(resolve, time); }); }
You test your program to see if it behaves the way you expect it to or if any error messages pop up. There’s a paradigm called Test-Driven Development (or TDD) that helps to automate this kind of thing, but I wouldn’t recomento to a complete beginner to programming, as it requires using libraries and writing even more code. If you’re comfortable with these things, however, check it out, it’s an awesome way to program. In JavaScript specifically, you check how the page answers to your inputs, and if there’s any red messages in the console.
I love learning from you so much. The biggest bummer to learning things about programming is people tend to over complicate things when they don't need to. I guess to sound super smart??? Every time I watch a video from you nothing is over complicated. It's stated just how it is. THANK YOU! Also thank you for teaching me about promises.
I agree with you 100% Grant.
The bad thing about most developers is that they are the ultimate flexers.
@@victorgasparoni 😐
I just come back and re-watch these videos, just to feel your positive energy. Thank you 😍
Can I just say, I love your energy, you're making this learning process really fun.
Hey Dan, just another quick tip to make your code slightly shorter. When you write .catch(err => console.error(err)) you can just write .catch(console.error) instead. This is the case every time you would call an arrow function with just one parameter, only to call another function on that parameter.
@Sph2329 do we need bind() here, I think the arrow syntax (even though not explicitly present) will take care of the context, so we need not fix "this" using bind IMHO.
I love your channel ! it's about 2 days that I found it. since I watched your first video about js, I search topics that I'm looking for, first.
I have never been so excited to learn programming 😊😊😊
can someone please make a 10 hour version of 5:45?
I fully endorse this project idea.
gph.is/2P7lNDP
HAHAHAHAHA OMG NO, I almost had an anxiety attack with this
Haha that was a struggle
@@bbit-solutions7004 this doesn't work
amazing explanation that takes time to actually how each component works in depth.
Simply... you are an excellent teacher !
oh my this is way easier than i thought
Your tutorials are awesome!
When you walk between frames it reminds me so freakin' much of logi mouse moving between screens :). Great tut, thank you !
you are a gifted professor
i just love the way you teach, it is just so engaging! thank you so much!
Could you do some more native javascript? I feel like it would be interesting
You really are a great teacher.
I was reading eloquent js for 4 days, and couldn't get this topic.
Thanks for video!
who's watching this in the year 3122?
11:11
Maybe you will be in one of your future incarnations
Great teacher on the earth 🌎.
despite knowing most of the stuff, it:s entertaining to watch. nice!
Very informative, and also entertaining. Thank you!!
My fav channel!!
Hi DAN! not supposed to be here, still on the p5js tutorials, I SHALL CATCH UP THOUGH! Peace & Love on the CodingTrain! CHOoOOOoOoooOOOoOCHooOOOoOOO
I know all this but you make it so interesting to watch so I like to watch anyway :D
Can’t wait for async/await since I’m not quite familiar with them
*fetch()* still isn't built into Node.js, so in the mean time you need to do *npm install node-fetch --save*
Great video! Thank you so much
Really like your ES6 explanations. Any plans to do more?
Daniel you're Genius!!
Thanks Daniel... very Useful do you have any video or plan of video where we get data from firebase using a searchbox?
Hi, you have a SetUp Function() then you have a NoCanvas Function.. Jusst curious! Does Javascript automatically create a canvas in the DOM? & if so/ or not... is NoCanvas a native JS function itself? or have you defined that elsewhere? Promises looking handy.
I'm learning a lot with your videos!
PS: ES stands for EcmaScript
Noob question: at 3:41 you have delay() called on line 3, but defined on line 7. How does this work? I thought you had to define before calling. I could be mixed up too as I have limited experience. Got the code bug and trying to learn.
Jason Bahr
Functions that are written like that are hoisted; it means that the program can run it, even though they are written somewhere else of where they are called. Every function notations have their pros and cons.
Please correct me if I’m wrong. I’m still a noob too.
How are the functions noCanvas() and createP() working ? Where are they defined ?
These are part of the p5.js library! p5js.org/
@@TheCodingTrain only first heard of p5 on your channel. Will check into it!
Did you created the pj5 library?
You should really cancel execution of the function after rejecting otherwise the program will be running the setTimeout to resolve a rejected promise which is a waste of system resources :)
Oh it’s fixed I’m the next video, which is unlisted :)
yeah, i goofed!
Good to hear it's fixed in the next one, but yeah it's really good to get in the habit of always returning if you reject or resolve a promise as I believe calling any of those functions more than once can result in undefined behavior?
Cole Erickson depends on what it’s doing, but yea. The promise itself will be fine since it can only resolve or reject once but doing the action anyway could cause some problems elsewhere in some cases
You Videos are excellent please make javascript AWS developer S3 videos 👍👍👍👍
anyone notice that the output from the resolve never got delayed? I applied this code inside a console and it delayed it by the time indicated, but the createP method displayed the message right away.
edit: i figured out my issue. The setTmeout() has to have a callback argument as follows and then the delay works:
if (isNaN(time))
reject(new Error(time + " is not a valid number"));
else
setTimeout(() => resolve("test resolved"), time);
*You're Just amazing!!!!!!*
I may have missed this..but what is the createP..his HTML id? or is that a js method that appends the return data?
It's part of the p5.js library, see: p5js.org.
Is delay, resolve and reject are JavaScript built in keywords?
Thank you very much really nice video. made simple and jokes are timely and interesting.
can you make video on javascript and ecmascript without p5.js
where does that resolve and the reject come from? is it a promise method?
No. It's just a callback passed to the Promise constructor. The name resolve and reject is just a convention, but you can name it anything, it doesn't really matter.
What I don't get is that when setTimeOut calls resolve, what does resolve do exactly? Is it a function which does nothing? Thanks
Promises are made to be broken. Does it work here as well?
My coworker told me you look like Hugh Jackman. Anyway thanks for the video man, love from PH.
Thank you!
Let CodingTrain = () => setTimeout(()=>♥️, 1000);
CodingTrain();
8:40 Yes, it works. But why.
You didn't put an else block around setTimeout and you don't return after you call reject. So even if the isNaN function returns true it should still execute setTimeout.
Does that mean the function which is passed to the Promise constructor automatically returns after the function passed in the second argument is called?
If yes, I don't like that. That should be in the control of the developer.
No. Pretty sure you have to manually return it, as it's also a matter of security.
kebman I didn't watched it all over again, but I think later (in another video(?)) he also noticed that he made a mistake at this point.
no it won't. by default what comes after and if it considered else.
It works because promises don't change after they settled (either fulfilled or rejected). So you cannot have a promise that will reject after 1 second, but then resolve after 2 second.
In this implementation the setTimeout still happens, the resolve function will be called (after the delay), but it won't change the rejected promise into a fulfilled one.
your just amazing please keep doing things just the way u r funny & simple
looks like we are heading times where java will be updating each few hours.
Hello, why I need to use resolve() in my code. If not, then will never execute. I'm not sure it is related to angular. I have new Promise(resolve,reject). I expected that it will continue to execute and auto return resolve and if any error will return rejected
Superb
10:35 - YMCA
Do you still write program people of year 3122?
how can I see my code in the browser? :(
using the Promise(resolve,reject) was almost felt to me like cheating in examination or plagiarism :(
2:00 aww 😂
Can anybody tell me what the noCanvas() function is for?
Just came back from the year 3122 just to keep my promise 🤧
where the react tutorials at. thank you
it's still relative)
Hello, guys am a little bit confused tried running similar code in vanilla javascript while it works, the timing is completely off. the function runs immediately in the browser.
delay(9000)
.then(document.write('Promise is sucessful'))
.catch(err => console.error(err))
function delay(time){
return new Promise((resolve,reject)=>{
setTimeout(resolve,time);
});
}
Hi I encountered a similar issue, my resolve was returned immediately without delay. Then I read that it's because I wrote it as setTimeout(resolve(), time) . Note the parentheses. It should be setTimeout(resolve, time) .
But I see that yours is written without parentheses, so it should run with delay though. That's strange.
I am the only one that is trying codes? @7:15 the code doesnt work, at least not for me. Where am i taking a mistake? Here is the code, maybe can someone tell me with just a look at it:
function setup() {
delay(1000)
.then(() => createP('Hello'))
.catch((err) => console.error(err));
}
function delay(time) {
return new Promise((resolve, reject) => {
setTimeout(resolve, time);
});
}
think its because he uses p5.js which you might not be using
nice
what is p5?
p5 is a library for JavaScript, for more: p5js.org.
The Anchor looks like Gilfoyle from Silicon Valley, LOL
Hi to all those watching in the year 3122! Sincerely, 2021
What was I talking-saying?
who is watching this at 3422! ... all the people during lockdown be like "well it felt like millennium, so me!" :D
came for self help...going with self doubt
{2021-12-16}
This is over-complicated. Use easier examples to teach brand new and difficult material.
How do you know that you have made any type of coding mistake? plz answer i am waiting!
You test your program to see if it behaves the way you expect it to or if any error messages pop up. There’s a paradigm called Test-Driven Development (or TDD) that helps to automate this kind of thing, but I wouldn’t recomento to a complete beginner to programming, as it requires using libraries and writing even more code. If you’re comfortable with these things, however, check it out, it’s an awesome way to program.
In JavaScript specifically, you check how the page answers to your inputs, and if there’s any red messages in the console.
Thanks
You could lookup a linter plug-in for atom
Thanks BROTHER!
Great video but your laugh is weird :P