0% found this document useful (0 votes)
47 views1 page

Lecture 9 - Conceptual Aside Syntax Parsers, Execution Context and Lexical Environments

When JavaScript code is run, an execution context is created that establishes the global object and 'this' value. The global execution context creates the global object (window in browsers) and sets 'this' to also refer to the global object. It also links any functions to the outer environment, unless running at the global level where there is no outer environment.

Uploaded by

Tim Pron
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
47 views1 page

Lecture 9 - Conceptual Aside Syntax Parsers, Execution Context and Lexical Environments

When JavaScript code is run, an execution context is created that establishes the global object and 'this' value. The global execution context creates the global object (window in browsers) and sets 'this' to also refer to the global object. It also links any functions to the outer environment, unless running at the global level where there is no outer environment.

Uploaded by

Tim Pron
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

Whenever a code is run in Jvascript, it is run inside an execution context.

The base executionncontext is the global execution context. Global means accesible
everywhere to everything in your code.

The Global execution context creates two things for you, automatically. 1. the
global object. 2. It creates a special variable called 'this'. The Javascript
engine is creating these two things for you whenver your code is run.

sample:
when a file is run, an execution context is created. and the exec context decided
the value of 'this'. that is why you can call this in the console.

'this' refers to the current window we are in. in the browser.

interestingly, there is an avaible object called window, the same object as 'this'.

window is the global obejct inside browsers. In node js its a different object.
Nvertheless, there is a global objetc being created.

Now, window refers to the window currenlty open. the tab in the browser. Separate
tab means seaparate window global object.

**at the global level, Global object window == 'this'

**global - in js, means "not inside a function"

**when one creates a global variable or function, these are attached to the global
object window. Therefore, when you run window in the console, you will see that the
global variables and functions that you created are actually inside the it.

ie. in console,

a == window.a

>outer environment - a link into the outer enviroment. if you're running code
inside the function, then the outer envroment is that which is ouside the fucntion.
When you are at the global execution context, then there is no outer environment.
that is null.

>summary
when you run a code, the execution context:
1. creates global object.
2. creates a special variable clled 'this', which, in browsers, is equal to window
in the global context.s
3. creates a link to the outer environent especially for non-globals - things
inside a function
4. runs your code

the execution context is the wrapper. and it did some additional stuff.

You might also like