async function fetchData() { const response = await fetch('https://api.example.com/data'); const data = await response.json(); return data; } fetchData().then(result => console.log(result)); console.log(data);
The variable data is declared inside the async function fetchData and is not accessible outside it. Trying to log data outside causes a ReferenceError.
import http from 'http'; const server = http.createServer((req, res) => { if (req.url === '/error') { throw new Error('Test error'); } res.end('Hello World'); }); server.listen(3000);
Throwing an error inside the server callback without a try-catch causes the Node.js process to crash, stopping the server.
Option B safely accesses subProp only if obj and prop exist. Other options either miss optional chaining on a property or incorrectly use it on a function call.
import EventEmitter from 'events'; const emitter = new EventEmitter(); emitter.on('start', () => { console.log('Started'); emitter.emit('process'); }); emitter.on('process', () => { console.log('Processing'); }); emitter.emit('start');
The 'start' event handler logs 'Started' and then emits 'process', which logs 'Processing'. So both lines print in order.
Asynchronous callbacks may run later and out of the original call order, making stack traces harder to follow and causing confusion during debugging.
