@alekseibodeev
Posted
Hi 👋 Perfect solution!
If you want to improve readability of asynchronous code I would recommend to check async/await syntax out. async/await is syntactic sugar on top of promises that makes your code feels like a synchronous one. For example:
Promises:
fetch(url)
.then((res) => res.json())
.then((data) => console.log(data))
.catch((err) => console.log(err));
async/await:
async function doStuff() {
try {
const res = await fetch(url);
const data = await res.json();
console.log(data);
} catch(err) {
console.log(err);
}
}
doStuff();