So i want to understand better what’s going behind the code. Using a Call stack so I can see what comes first what next and how it work.
But what is the best Call stack and where do I find them. Does anyone here have experiance with them? so yes what do u use? I am basicly asking here like: what sociale media site is best? Facebook twitter our instagram. But then for call stacks
The look like
Hi @KittyKora 
This is what happens when the code is run:
- When
sayAll()
gets executed, an empty stack frame is created. It is the main (anonymous) entry point of the program.
-
sayAll()
then calls sayHello()
which is pushed into the stack.
-
sayHello()
returns and prints “hello my name is Ed” to the console.
-
sayHello()
is pop off the stack.
- The execution order then move to
sayAll()
.
-
sayAll()
then calls sayAge()
which is pushed into the stack.
-
sayAge()
returns and print “my age is 25” to the console.
-
sayAge()
is pop off the stack.
- The execution order then move to
sayAll()
and sayAll()
is pop off the stack.
- Last console.log(‘Final’) returns “Final” to the console.
- Clearing the memory.
call stack - https://medium.com/@gaurav.pandvia/understanding-javascript-function-executions-tasks-event-loop-call-stack-more-part-1-5683dea1f5ec
2 Likes
we don’t all hav godlike powers like you do…
@KittyKora you can check link also for reference.
I did check the link and it just explains what a call stack is and where to find the most basic of it. If there is an error and then it only shows a small part of it. But thats not what i am looking for. I want to use it even without the error message. and see the whole picture. maybe myquestion wasn’t clear enoug i edited it :3
A call stack isn’t a type of debugging program, there aren’t different call stacks to pick from. It’s the call stack, and it is literally the program executing, function by function, as @dev-313 says
- Every error has a
stack
property that you can view
console.trace
(as opposed to console.log
) will print the stack
- The step debugger in the console lets you step through the program: you are stepping through function calls with it, ie the call stack. You can put
debugger
calls anywhere in the code to cause program execution to pause at that point (and trigger the step debugger to open if it isn’t already open), or you can do it manually from the step debugger (generally more useful)
2 Likes
Would you be so kind to explain this more simple I don’t understand half of what you are saying?
What is a stack property?
and a console.trace?
You understand what console.log
is? That lets you log arbitrary things to the console. There are a load of other functions as well that let you log specific things to the console that you can use instead – for example if you have an object, you can use console.table(thatObject)
to print the object in a formatted table in the console.
console.trace()
is one of those functions, it prints a stack trace. If you put it in a function, it will print the call stack in the console when the function runs.
Re Errors, when JS code throws an error, there is an Error object which has certain properties. eg message
which is the message that gets printed to the console (eg “Error: undefined is not an object”). The Error object also has a stack
property that shows the call stack at the point of the error. In the console, Errors show red, and there’s normally a little arrow you can click which expands the error shows the properties, including the stack.
1 Like
Thanks for explaing that one :3 im still a beginner here and have a hard time understanding things here.
1 Like