Skip to content

Instantly share code, notes, and snippets.

@kpion
Last active May 13, 2018 05:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kpion/1a1b70b1f97e1e604f5421eed5efc54f to your computer and use it in GitHub Desktop.
Save kpion/1a1b70b1f97e1e604f5421eed5efc54f to your computer and use it in GitHub Desktop.

Javascript new Error().stack; output examples

<script>
  let stack = new Error().stack;
  console.log(stack);
</script>

All browsers return a string delimited by a \n. Assuming the file full path is http://localhost/yalog/experiments.html and code in the file is similar to:

function first() {
    second();//line 17
}

function second() {
    const stack = new Error().stack;//line 21
    console.log(stack);
}

first();//line 28

Chrome/Opera returns e.g. this:

Error at second (http://localhost/yalog/experiments.html:21:31) at first (http://localhost/yalog/experiments.html:17:17) at http://localhost/yalog/experiments.html:28:9

Firefox:

second@http://localhost/yalog/experiments.html:21:31 first@http://localhost/yalog/experiments.html:17:17 @http://localhost/yalog/experiments.html:28:13

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment