DO NOT USE: WRONG EXAMPLE
WITHOUT CLOSURE IN THEN()
by RomainMazB
HTML
<html>
<body>
<ul id="fakeConsole"></ul>
</body>
</html>
JavaScript
$(document).ready(function(){
function resolveAfter2Seconds() {
return new Promise(resolve => {
setTimeout(() => {
resolve('resolved');
}, 2000);
});
}
async function asyncCall() {
consoleLog('calling');
var result = await resolveAfter2Seconds();
consoleLog(result);
// expected output: 'resolved'
}
function consoleLog(message) {
$("#fakeConsole").append('<li>'+message+'</li>')
}
asyncCall().then(consoleLog('then calling'));
});