JavaScript Array Sorting Itself
index.html style.css script.js const arr = [20, 5, 100,1, 90, 200, 40, 29]; for(let item of arr){ setTimeout(() => console.log(item), item) } CONSOLE 1 5 20 29 40 90 100 200
A JavaScript editor shows an array being processed with setTimeout, while the console prints the values in ascending order rather than their original order. The joke is that asynchronous callbacks with numeric delays make the numbers appear sorted by execution time, creating a surprisingly satisfying result for a programmer. EN: A JavaScript editor shows an array being processed with setTimeout, while the console prints the values in ascending order rather than their original order. The joke is that asynchronous callbacks with numeric delays make the numbers appear sorted by execution time, creating a surprisingly satisfying result for a programmer.
- @ithueti / 3694 2021-02-10
- Type
- image
- Size
- 800×755 · 34.0 KiB
- Mood
- satisfying, nerdy
- Language
- en
- Added