DEV Community

Cristian Fernando
Cristian Fernando

Posted on


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

Explica este c贸digo JavaScript

Dificultad: Intermedio

const randomNumber = () => {
  return new Promise((resolve, reject) => {
    let random = Math.floor(Math.random() * 10) + 1;
    if(random >= 5){
      resolve(`Bien... ${random}`)
      reject(`Mal... ${random}`)

  .then(x => console.log(x))
  .catch((error) => console.log(error))
Enter fullscreen mode Exit fullscreen mode

A. Dependiendo del valor de random imprimir谩 Bien o Mal
B. Promise { <pending> }
C. Promise { <fulfill> }
D. Ninguna de la anteriores

Respuesta en el primer comentario.

Top comments (1)

duxtech profile image
Cristian Fernando

A. Dependiendo del valor de random imprimir谩 Bien o Mal

En este ejemplo el estado de la promesa cambiar谩 en funci贸n del valor de la variable random, cuando cambie este valor la promesa se volver谩 a evaluar y podr谩 ser satisfecha o no.

The JavaScript Brief

1. Top 5 MERN STACK projects to improve your practical understanding

Boost your MERN Stack development skills by undertaking interesting beginner projects. These five engaging projects cover web applications and range from social media website applications to geo-social networking maps. Hone your understanding and apply modern techniques backed up by hands-on experience.

2. How To Optimize Your React App鈥檚 Performance

Learn the best optimizing techniques to make your React applications faster and more efficient. Focusing on the identification of performance bottlenecks and common pitfalls to avoid, these optimization strategies will keep your applications running smoothly even when faced with growing complexity.

3. A story of let, const, object mutation, and a bug in my code

In the pursuit of bug-free code, explore an incident involving a mix-up between const and let, making sure your custom code works effectively with third

party documentation. Discover best practices on program flow and learn about JavaScript's unpredictable aspects to ensure your core code is robust.