What is onerror() Method in JavaScript?

JavascriptWeb DevelopmentFront End Technology

The onerror event handler was the first feature to facilitate error handling in JavaScript. The error event is fired on the window object whenever an exception occurs on the page.


You can try to run the following code to implement onerror() method in JavaScript −

            window.onerror = function () {
               alert("An error occurred.");
      <p>Click the following to see the result:</p>

         <input type = "button" value = "Click Me" onclick = "myFunc();" />
Updated on 19-Jun-2020 08:54:39