Skip to main content
Journey Uncommon Logo
JourneyUncommon
hardNodeJSevent loop phasesSingle-choice MCQ

A senior asks why the second 'setImmediate' fires before the 'setTimeout' here even though the timeout is 0. What is the precise reason?

const fs = require('fs'); fs.readFile(__filename, () => { setTimeout(() => console.log('timeout'), 0); setImmediate(() => console.log('immediate')); });