Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 564377
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T12:45:36+00:00 2026-05-13T12:45:36+00:00

For simple javascript debugging I’ll use alerts to show variable values and the like.

  • 0

For simple javascript debugging I’ll use alerts to show variable values and the like. Is there a way to get the current call stack in javascript to be able to display it in an alert?

Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T12:45:36+00:00Added an answer on May 13, 2026 at 12:45 pm

    Quick and dirty in Gecko-based browsers:

    new Error().stack
    

    You can also manually trawl some of the stack using Function.prototype.caller:

    var thisFunction = arguments.callee;
    var caller = thisFunction.caller;
    var callerCaller = caller.caller;
    // ...and eventually, assuming no recursion:
    var bottomCaller = ...;
    assert(bottomCaller.caller === null);
    

    One (possibly large) caveat of the .caller trick is that it doesn’t handle recursion — .caller looks from the top of the stack downward to find the first instance of the function in the stack and then returns its immediate caller, so without being careful you can loop infinitely looking up callers.

    Another caveat to caller is that, going forward, if any of your code uses ECMAScript 5’s strict mode, the caller property of strict mode functions (or of functions which have themselves been called from strict mode functions) is a so-called “poison pill” which throws a TypeError when accessed. The caller property of “bound” functions (those created by ES5’s Function.prototype.bind method) is also a poison pill. These restrictions break the generic stack-walking algorithm, although one could imagine use-specific ways to work around this (entry and exit annotating functions, perhaps).

    Do note that stack-walking like this isn’t a great idea in production code (as a quick hack for debugging it’s fine, tho); at the moment walking up the stack as in the latter example is somewhat expensive in Mozilla’s JS engine, and it’ll probably throw you out of machine code and back into interpreted code. Also, the stack-walk is O(n2), which might matter if you tend to have complex, deep stacks.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm writing a simple Javascript library that makes use of some WebGL code. I'd
I use a simple JavaScript confirm function that is used by all pages in
I'm considering creating a simple remote debugging application for Javascript. Actually, I want to
For the purposes of debugging I need to make Richfaces use non-minified JavaScript. Is
With the increased power of JavaScript frameworks like YUI, JQuery, and Prototype, and debugging
Is there a (simple) way to echo some variables from a Codeigniter controller to
Got a simple Javascript program here to accept and check a password. It should:
I have a very simple JavaScript/jquery code which won't just work correctly. The problem
I have simple JavaScript snippet: var obrazek = [{nazwa: "Sniadanie", wiek: 100, autor: "Alicja"},{nazwa:
I have a simple javascript question (I'm not a javascript expert, so excuse me

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.