0

I'm new in JavaScript and I'm learning how JS works behind the scenes and lately I'm trying to understand the execution context and I read some articles in google telling that it's a fancy word to describe the environment in which our code is executed. so from what this environment is constituted?

Does it constituted from functions, the "this" keyword, variables, objects?

Please make it brief I need a simple explanation I'm still a beginner.

Saugat Bhattarai
2,7904 gold badges26 silver badges34 bronze badges
asked Nov 27, 2018 at 5:40
1
  • 1
    The execution context rarely is the environment itself when concerning this value. Are you sure you haven't read about "environment records"? Commented Nov 27, 2018 at 6:54

1 Answer 1

2

You can pretty much think of JS environment in terms of who started the JS runtime.

If you are running your JS program using Node.js from the terminal, then Node defines the environment - what all libraries and default objects are available to you.

If your JS is part of a web page, then the browser creates a JS runtime for each original tab, and all the JS does is confined within that runtime. For example, you can't look up a DOM element in an adjacent browser tab which you didn't 'popup'.

In the Node.js case, the environment gives you support for file access, network access, database access etc. You would be starting your program like this:

$ node app.js

In the browser environment, you have access to window, document, XMLHttpRequest etc., which are inbuilt to that environment. You would just be adding a script tag in a HTML document to get your script into the picture:

<script src='/path/to/myscript.js'/>
answered Nov 27, 2018 at 5:53
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.