What is the use of .stack property in JavaScript?

JavascriptFront End TechnologyObject Oriented Programming

The stack property of Error objects offers a trace of which functions were called, in what order, from which line and file, and with what arguments. The stack string proceeds from the most recent calls to earlier ones, leading back to the original global scope call. It is similar to the stack trace in Java.


function a() {
   throw new Error("error");
catch(e) {


This will give the output −

Error: error
   at a (<anonymous>:2:11)
   at <anonymous>:6:5

Note − Stack is a non-standard property and may not be available in all environments.

Published on 27-Nov-2019 09:44:11