Long description

Back

The JavaScript code consists of 12 lines of code. Line 1: StartCommand let EndCommand g1 equals open double quotes variable with global scope close double quotes semicolon, at indentation level 0. Line 2: function parent1 open parenthesis close parenthesis open curly brace, at indentation level 0. Line 3: StartCommand let EndCommand f o o equals open double quotes within parent1 close double quotes semicolon, at indentation level 1. Line 4: function child1 open parenthesis close parenthesis open curly brace, at indentation level 1. Line 5: var bar equals open double quotes within child1 close double quotes semicolon, at indentation level 2. Line 6: debugger, at indentation level 2. An arrow from line 6 points to the DevTools window at the right. The window is titled double quotes Debugger paused below which Scope is written. There are four lines of code with their labels written one below the other. Label: Local. The first line of code: bar colon open double quotes within child close double quotes. The second line of code: Operator this colon Window. Label: Closure. The third line of code: foo colon open double quotes within parent1 close double quotes. Label: Script. The fourth line of code: g 1 colon open double quotes variable with global scope close double quotes. Label: Global.

Line 7: return foo plus open double quotes close double quotes plus bar semicolon, at indentation level 2. An arrow labeled Nothing surprising here ellipsis A nested function has access to variables in its parent points from line 7 to line 3

Line 8: close curly brace, at indentation level 1. Line 9: return child1 open parenthesis close parenthesis semicolon, at indentation level 1. Line 10: close curly brace, at indentation level 0.

Line 11: StartCommand let EndCommand value equals parent open parenthesis close parenthesis semicolon, at indentation level 0. Line 12: alert open parenthesis value equals open double quotes plus value close parenthesis semicolon, at indentation level 0. An arrow points from line 12 to the Alert window at the right. The alert window reads value equals within parent1 within child1 and has an OK button at the bottom. Note: The value variable is going to simply contain the value returned from the inner child1 open parenthesis close parenthesis function. Note: If you examine the inner function with debugger, you will see that it displays what is in local forward slash function scope, script forward slash global scope, as well as what’s contained within the closure for this function.

Back