4 ms·
Callbacks are just functions, promises are part of a standard library (not the language), only async/await is part of the language itself.
by beeboobaa 3y ago
Callbacks are just functions, promises are part of a standard library (not the language), only async/await is part of the language itself.
- lucideer 3y agoPromises are part of the language. Async/await are just syntax around Promises - they're all 1 feature.
- anamexis 3y agoTechnically, await isn't specific to promises. It works with any then-able object.
- culi 3y agoWhat are other then-able objects besides Promises?
- anamexis 3y ago{ then: (callback) => callback("foo") } Anything that has the same signature as a Promise. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise#thenables https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe...
- culi 3y agoOkay, but nothing built in to the standard. In fact, even the docs you linked only point out that other implementations of Promises are "then-able". I guess I was under the impression that there were other, non-Promise, examples of thenables
- lucideer 3y agoThe main use I've seen is returning "promise-like" objects in functions that can be sync or async depending on params but are expected to have a common return type.
- culi 3y agoTo add to this, async/await is not a complete replacement. As in, it doesn't mean you'll never have to write `Promise` in your code. You still have to rely on Promise.all when you want to run multiple promises concurrently instead of sequentially