DEV Community

smol
smol

Posted on

Day 1/30 back to DSA challenge

Did revision of my previous notes on dsa and a topic of Javascript which is Promises and Callback hell
DSA:
Started with first problem Two Sums problem and how solved it using hashmap and complement
It is not actually storing the element and taking the sum to the target rather it is taking the complement and then storing it and checking if we find that in the next coming nums if we find it we return the index of these numbers

Promises:
we have a concept of asynchronous in js
And to understand that we have to understand what is synchronous? so basically it means that the code will execute line by line and when we have any line which might take some time to give us the output such as fetching the API (if we go for a real world example) then all the other lines after this will be blocked and will not execute until the previous one is completed
so here comes asynchronous which mean that it will continue to do the work simultaneously, so say this line is taking 2 sec then it won't care if it is completed or not it will jump to output the next line and when 2 sec is completed we can see the output then
here callback is used which mean an argument in function which has to be executed later
and when we have nested callbacks it is called callback hell and to overcome this we are using promises

So this is what i learned today
I am going to be so much more productive in my next challenge I Promise haha

Top comments (0)