To get a JavaScript stack trace, simply add the following in your code. It will display the stack trace −
Example
<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
