promise wait for function to finish js code example
Example 1: wait for promise javascript
const userCount = await getUserCount();
console.log(userCount); // 12345
Example 2: how to wait for a function to finish in javascript
function doFirst() {
return new Promise(function(resolve, reject) {
//do a thing
if (){
return reject(value);
}
resolve(value);
});
});
}
async function doSecond() {
var outputValue = await doFirst();
console.log(outputValue);
}