Learning object 15 of 100
Function return-value visualizer
Step into and out of function calls. The call stack shows which function is running, and each return value replaces the call that produced it.
Loading…
What it shows
Calling a function pushes a frame on the call stack with its own parameters and local variables. return ends the function, removes its frame and hands its value back to the caller, where the call expression is replaced by that value. Composed calls such as format(addTip(bill)) run from the inside out.
Guided experiment
- In Return values, step until the stack shows
subtotal. What are qty and price? - In Composition, predict the order in which the three functions finish.
- In Print or return, compare the values of x and y at the end.
Predict
In money(addTip(40, 25)), which function finishes first?
Related
Lessons: Lesson 21: Function declarations and expressions, Lesson 23: Return values, Lesson 25: Combining functions into applications
Projects: Project 1: Interactive Tip Calculator
Source: web/assets/js/objects/object-015.js in the companion repository.