1: var a = 'Is';
2: function test() {
3: var a = 'Fun';
4: function again() {
5: var a = 'JavaScript';
6: alert(a);
7:
8: }
9: again();
10: alert(a);
11: }
12: test();
13: alert(a);
Before execution of Line 1: A variable a
, initialized with the value undefined
, and a function test
, are added to the current lexical environment. If this code is run in the global context, these variables will be added as properties on the global object.
Line 1: The string 'Is'
is assigned to the variable a
in this lexical environment.
Line 12: The hidden method [[Call]]
is invoked on the function test
, and a new execution context is created, with a variable a
(with an initial value of undefined
) and a function again
added to its lexical environment.
Line 3: The string 'Fun'
is assigned to the variable a
in this lexical environment.
Line 9: The hidden method [[Call]]
is invoked on the function again
, and a new execution context is created, with a variable a
(with an initial value of undefined
) added to its lexical environment.
Line 5: The string 'JavaScript'
is assigned to the variable a
in this lexical environment.
Line 6: The host-provided window.alert
function is invoked, passing the value associated with variable a
in this lexical environment ('JavaScript'
).
Line 10: The host-provided window.alert
function is invoked, passing the value associated with variable a
in this lexical environment ('Fun'
).
Line 13: The host-provided window.alert
function is invoked, passing the value associated with variable a
in this lexical environment ('Is'
).