Search This Blog

Monday, June 24, 2019

Print call stack in javascript

From https://til.hashrocket.com/posts/478143b559-print-call-stack-on-javascript

Print call stack on Javascript

If you want to print the javascript **call stack** you can use:

```javascript
console.log(new Error().stack);
```

Here it is an **example**:

```javascript
function firstFunction() {
    secondFunction();
}
function secondFunction() {
    thridFunction();
}
function thridFunction() {
    console.log(new Error().stack);
}
firstFunction();

//=> Error
//    at thridFunction (<anonymous>:2:17)
//    at secondFunction (<anonymous>:5:5)
//    at firstFunction (<anonymous>:8:5)
//    at <anonymous>:10:1
```

h/t @rondale_sc

viniciusnegrisolo
June 10, 2016