DEV Community

Discussion on: If Javascript Is Single Threaded, How Is It Asynchronous?

Collapse
 
timepp profile image
timepp

This is mostly equivlant with the following code

let arr = [10, 100, 500, 20, 35];
let sorted = 0
for (let i = 0; sorted < arr.length; i++) {
    for (const v of arr) {
        if (v === i) { 
            console.log(v);
            sorted++;
        }
    }
}
Enter fullscreen mode Exit fullscreen mode