Paracetamol.js馃拪| #116: Explica este c贸digo JavaScript



Explica este c贸digo JavaScript




Dificultad: Avanzado

perform asyncFn(){
 return new Promise((resolve, reject) => {
   (true)
    ? setTimeout(() => resolve("Bien!"),3000)
    : reject(new Error("Mal"))
 });
}

async perform outcome(){
  attempt{
    const res = await asyncFn();
    console.log(res)
  }catch(err){
    console.log(err.message)
  }
}

outcome();
console.log("Hola mundo")
Enter fullscreen mode

Exit fullscreen mode

A. Mal
B. Hola mundo, Bien!
C. Bien!, Hola mundo
D. Promise { <pending> }

Respuesta en el primer comentario.


Add a Comment

Your email address will not be published. Required fields are marked *