| Can you write difference between Promises and Observables
Before going directly to difference between these two i will discuss something about asynchronous features in the JavaScript. Here we know flow of program occurs independently in computer this is called Asynchrony. And this does not wait for a task to get finished and moved moves to the next task.Now question arise we will be take care of this unfinished task. SO answer is background co-worker works handle those unfinished tasks. And another questions is who will handle the data that is returned and answer is Promises, Observables, callbacks and many more of them.
Now move to difference between these 2:-
Promises
(1)Promises are used to handling async requests
(2)Promises are not lazy like observables and promises are execute immediately.
(3)Promise can only provide a single value
(4)We cannot cancel promise becasue cancel feature is not there
(5)promises does not have any operators in their bucket
Observables
(1)Observable are also used to handle asyn requests
(2)Observable are very lazy so we have to subscribe observable to get the results.
(3)On the other hand observable can handle multiple values and also give multiple values.
(4)We can cancel observables by unsubscribing it using the unsubscribe method
(5)There are many operators like map, forEach, filter etc in observables | | |