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

Why does the relative order of setTimeout(fn, 0) and setImmediate(fn) inside the main module become deterministic when both are placed inside an I/O callback?

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