How can I get a stack trace for a JavaScript exception?

JavascriptWeb DevelopmentFront End Technology

To get a JavaScript stack trace, simply add the following in your code. It will display the stack trace −

Example

 Live Demo

<html>
   <head>
      <script>
         function stackTrace() {
            var err = new Error();
            return err.stack;
         }

         console.log(stackTrace());
         document.write(stackTrace());
      </script>
   </head>
   <body>
      <p>Stacktrace prints above.</p>
   </body>
</html>

Output


raja
Published on 23-Feb-2018 11:31:28
Advertisements