In what order will the numbers 1-4 be logged to the console when the code below is executed? Why? | Sololearn: Learn to code for FREE!
Nouvelle formation ! Tous les codeurs devraient apprendre l'IA générative !
Essayez une leçon gratuite
0

In what order will the numbers 1-4 be logged to the console when the code below is executed? Why?

(function() { console.log(1); setTimeout(function(){console.log(2)}, 1000); setTimeout(function(){console.log(3)}, 0); console.log(4); })();

3rd Oct 2018, 9:18 AM
MUHAMMAD ILYAS
MUHAMMAD ILYAS - avatar
3 Réponses
0
1 4 3 2 Because the delay value can be thought of as a minimum delay. Actual delay may vary as the program simply makes its best effort. https://stackoverflow.com/questions/33955650/what-is-settimeout-doing-when-set-to-0-milliseconds/33955673
3rd Oct 2018, 10:05 AM
Janning⭐
Janning⭐ - avatar
0
Hii
9th Dec 2022, 5:46 AM
Sai Pavan Etikyala
Sai Pavan Etikyala - avatar
- 1
what order will the numbers 1-4 be logged to the console when the belo 7. function() { console.log(1); setTimeout(function()(console.log(2)), 1000); SetTimeout(function()(console.log(3)), 0); 10: O 1432 1234 2314 O 1423
7th Oct 2022, 10:29 AM
Modala Sravani