DEV Community

Discussion on: Top Interview Questions for Backend Developers(Node)

Collapse
 
jzombie profile image
jzombie

Nice article, and I like the illustrations.

I think there's one particular thing that might be a little skewed, but feel free to correct me if I'm wrong.

My opinion on the single-threaded is, instead of "one function executed at a time," it would be any given synchronous code piece, regardless of it is in a function or not.

The example that comes to mind for that is if you had a never-ending do-while loop and were repeatedly calling a function on each iteration, any asynchronous code which hasn't yet run, which was defined before that loop was set, will probably not get the chance to run as it would probably be blocked by the synchronous loop iterations.

Collapse
 
jazzbrown1 profile image
Jazz Brown

Hey thanks good article. But to be nitpicky, that is because async in JavaScript isn't really asynchronous, in most other languages you would expect async code to be on a different thread and be able to run simultaneously. And in JS all code runs on a single thread so I'd say single thread vs async is a bit out. It should be syncronous Vs async. And in the answer I would explain as jzombie said that even async code is on the single thread and can block other async functions from running.

Collapse
 
abhishekraj272 profile image
Abhishek Raj

Yes the question was in context of JS, because JS is single threaded, async language. So the question is what's the difference between the two.

Will modify the question as well as answer for better understanding.

Collapse
 
abhishekraj272 profile image
Abhishek Raj

Thanks for the appreciation and correction.
Will correct it 🙌🏼