What is the point of the concept ‘promise’

I been watching ‘Promise’ videos and still dont understand the concept. When is it most relevant to use it?
6 Replies
chrono1913
chrono19133y ago
i saw an example where they use an if statement in it and im wondering why dont they just use the if statement without the promise
13eck
13eck3y ago
Promises are functions that will eventually resolve to a value (or fail to resolve to a value) but how long it takes to do so is never known. Promises are for things like HTTP requests (using fetch()) where network latency makes it impossible to know when/if it'll fulfill. Promises also give control back to the JS runtime so while it's waiting the rest of your code can still run.
Joao
Joao3y ago
Promises also give control back to the JS runtime so while it's waiting the rest of your code can still run.
Just want to emphasize, this is the main reason we use promises in the first place. We don't want our code to idle doing nothing while it waits for the result of a network request to come back. This could be 30, 100 or 2000 milliseconds which may not sound like much but it's quite a lot.
chrono1913
chrono19133y ago
Ok now I get it thank you for the explanation
Want results from more Discord servers?
Add your server