JavaScript · Senior · Question 5 of 75
How do you globally track unhandled promise rejections in the browser?
- ✓Correct answer: The
unhandledrejectionevent onwindow - 2The
errorevent ondocumentwith apromiseflag - 3The
Promise.onErrormethod at the start of the app
Explanation
window.addEventListener('unhandledrejection', e => report(e.reason)) is the standard way to send such errors to monitoring. Synchronous unhandled errors are caught by the error event on window. There's no Promise.onError method.