We're using the promise of returning a résumé in place of an actual resume. Just as the search for the applicant's resume takes time to complete.įor that reason, the interviewer decides not to sit around doing nothing, so they begin interviewing the candidate based on the promise of a résumé delivery. Instead, it returns a promise that it will eventually provide the value at a later time.Ī promise in JavaScript is asynchronous, meaning it takes time to resolve or finish. The code does not directly or immediately return a value. The roommate promising to find the résumé and texting back is synonymous with how we define a promise in JavaScript. On the other hand, if the roommate finds the résumé, he will happily tell his friend that he was successful, and he will go ahead and FULFILL his hopes of getting a job. When that happens, the interview will end and the interviewee will be rejected. As we discussed before, if he didn't find the résumé, he will share this failure with you along with the reason why he didn't find it. But ultimately, his employment still depends on the FINAL STATUS of his résumé. The interviewee answers all the questions he is asked. At that time, the interviewer sets the status of the résumé delivery to PENDING. In the meantime, the interview continues as planned, and the interviewer holds on to the promise of finding the résumé, and not the actual résumé. For example, he may text this message over to his friend who's interviewing: “Sorry, I couldn’t find your résumé because the key to your safe is missing.” His roommate PROMISES to text back as soon as he has something to report.Īssuming the résumé is eventually found, he can text back: “Successful, I found your resume!”īut if he doesn't find it, he is supposed to text back a failure message with the reason why he couldn't find the résumé. He pleads with his roommate to help find his résumé. He quickly calls his roommate over the phone and asks him for help. Luckily for him, he has a roommate who was still at home at that time. When his interview session is about to begin, he realizes that he has forgotten his résumé. Imagine that you are interviewing job seekers for a position at your company.Ī young man frantically comes in for an interview. I will also show you how to use promises in your JavaScript with some examples. So in this article, I will be telling you a short story which explains what promises are and how exactly they work. People don't understand what a promise is in JavaScript is because they don't really know what it is about and how it behaves in simple and relatable terms. I have read a lot of articles on promises and the problem is that many of these guides don't explain them in a relatable way. So I decided to expand this into an introductory tutorial on JavaScript promises. I recently published this as a thread on Twitter and was blown away by the responses. If you're a JavaScript beginner, you might be struggling to understand what a promise really is.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |