Why this matters
Prevents silent drops and resource leaks.
When subscribing to streams/listeners, always provide an error handler and a deterministic unsubscribe/cleanup path.
Prevents silent drops and resource leaks.
Side-by-side examples engineers can pattern-match during review.
emitter.on('data', onData); // no error/cleanupemitter.on('data', onData); emitter.on('error', (err)=>logger.error('stream',{err})); const off=()=>emitter.off('data',onData);ws.onmessage = onMsgws.onmessage = onMsg; ws.onerror = onErr; ws.onclose = onCloseFrom the same buckets as this rule.
Check if loops use equality operators (== or !=) in termination conditions. These can lead to infinite loops if the condition is never met exactly. Instead, use relational operators like < or > for safer loop termination.