Solution Review: Debugging 101
Explore how to trace variable values in JavaScript by understanding scope changes, including global, local, and lexical scopes. Learn to debug effectively by analyzing function effects on variables and proper use of scope for returning correct values.
We'll cover the following...
Solution
The solution needs us to trace the code to see what could be the potential values of the variables in each highlighted lines. The best approach would be to start from the first line of code and list out variables and their assigned values. However, one thing to look out for is when the scope changes. While at the same time we will be looking for the variable that we need to eventually return such that the returned value is correct.
First, trace the code to see the potential values of variables in all highlighted lines. The best approach is to start from the first line of code and list out variables and ...