javascript await
await Promise(resolve => setTimeout(resolve, ms));
//or
(async () => {
await Promise(resolve => setTimeout(resolve, ms));
})();
javascript await
await Promise(resolve => setTimeout(resolve, ms));
//or
(async () => {
await Promise(resolve => setTimeout(resolve, ms));
})();
await javascript
If the value of the expression following the await operator is not a Promise, it's converted to a resolved Promise.
async await js
fetch('coffee.jpg')
.then(response => {
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
} else {
return response.blob();
}
})
.then(myBlob => {
let objectURL = URL.createObjectURL(myBlob);
let image = document.createElement('img');
image.src = objectURL;
document.body.appendChild(image);
})
.catch(e => {
console.log('There has been a problem with your fetch operation: ' + e.message);
});
await javascript
The await operator is used to wait for a Promise. It can only be used inside an async function within regular JavaScript code; however it can be used on its own with JavaScript modules.
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us