Skip to main content
Journey Uncommon Logo
JourneyUncommon
mediumNodeJSprocess.nextTick vs setImmediateSingle-choice MCQ

When both a setTimeout(fn, 0) and a setImmediate(fn) are scheduled from inside an I/O callback (e.g. an fs.readFile callback), which runs first and why?

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