What is the difference between synchronous and asynchronous functions?
- Synchronous functions block the execution until they finish.
- Asynchronous functions allow other code to run while waiting for operations (like
I/O) to complete.
// Synchronous (blocks event loop)
const data = fs.readFileSync('file.txt');
// Asynchronous (non-blocking)
fs.readFile('file.txt', (err, data) => {
if (err) throw err;
console.log(data);
});