Javascript Stack Trace

If you’re writing javascript and making a package, designing an API, or working with other developers, you should output helpful error messages if something unexpected happens. Printing the stack trace is a good way for the web developer (or just you 😆) to debug and figure out what went wrong where.

function catchIt() {
    try {
        throwIt();
    } catch (e) {
        console.error(e.stack); 
    }
}
function throwIt() {
    throw new Error('');
}

catchIt();

/*
 Error
 at throwIt (<anonymous>:8)
    at catchIt (<anonymous>:1)
    at <anonymous>:1
*/

Read more about it here

Instagram Post