DEV Community

Cover image for How to Explain to a 2 years-old Kid what a Promise is in JavaScript
Roberto Hernandez
Roberto Hernandez

Posted on • Originally published at Medium

How to Explain to a 2 years-old Kid what a Promise is in JavaScript

In December 2019, during holiday time, I traveled to Los Angeles, I didn't go on vacation. I spent my time there working remotely. I was so lucky to do that kind of stuff thanks to my current company.

So, one day my two-half-years-old Son, while I was working remotely, he asked me. Dad, what is a surprise? and I told him, Let’s see my little friend; a surprise is something that you don't know yet now but you will know at some moment some seconds later he asked me again, dad what a surprise is? and I answered him again, again and again until I finally said to him. Imagine your aunt “Chayo” has something in El Salvador, your country, which is waiting for you, is a gift for you but you don't know what that gift is, for now. You will see what that something is about until you come back and finally your aunt “Chayo” brings it to you.

So, after he was incessantly asking again the same question I though. how I could explain to him what a promise is in JavaScript. I had two problems, first I needed to explain what I do (What a programmer does) and the second problem was to explain what that hell a promise is in JavaScript.

Hard definition of promise

A promise is an object that may produce a single value some time in the future — Eric Elliot

Answer tough concepts to old people

Lately, I faced repeatedly the same struggle. I met new people, especially old guys and others who are completely far away from the software world. And they asked several questions. Actually, hard questions. Sometimes is hard to explain to them in a really easy and understandable manner. Ok, I will talk about this later. Let's jump into the point of this post.

Answer what I do to my little Son

First, I needed to answer him what I do and what that hell a programmer does. I told him, dad work on the computer the whole day. He spends his day typing in. There is a fun game on the computer where he needs to play typing letters.

Answer what I was working on

I am working on a fun game called “JS”. Here you can play with surprise, promises, other computers, other peoples, etc and I am now building a promise in that game called JS. Did you remember the game name, right?. It's called “JS”.

Let’s play my son

I will tell you what a promise is. But, first, remember you are so clever and I am completely sure you will understand this game. right?. Let’s start to play.
Tell me which is a toy you really want that mom or dad give it to you this year. Just after I asked him he answered quickly. A trumpet, yes a trumpet, Dad!. He answered! Wow, that is a great decision, my love. I said to him!

The Promise

So, I will give you that trumpet on December 24. It’s a promise between us. But first, to get that toy and close out our promise there are some things you need to know. A promise has three states which depend on how you do the things until you get it or not.

1- Pending
2- Resolved
3- Rejected

Don't worry my son about that. Now we have a promise, so it is in a pending state until the day comes and if you keep doing things well the promise will be successful. You will resolve your biggest wish for this year, your trumpet. Really nice, right?. Otherwise, we will need to close our promise and it will be rejected and you will not get the trumpet. are you agree with this? I asked him. His answer was, yes Dad, yes Dad.

So, now it is time to visualize how that promise will work over the next days. I told him.
Promise

Now you have more understanding of what a promise is and all things around it and since we already have a promise between us the next part I will show you is what I am typing in my computer to build that promise. See the next part. All your wishes are in.

Thanks for reading! I really appreciate your priceless time!

Support and follow me on my blog and Medium

Top comments (0)