In the book “Scope and Closure” there is this paragraph:
Let’s meet the cast of characters that interact to process the program var a = 2;, so we understand their conversations that we’ll listen in on shortly:
- Engine: responsible for start-to-finish compilation and execution of our JavaScript program.
- Compiler: one of Engine’s friends; handles all the dirty work of parsing and code-generation (see previous section).
- Scope: another friend of Engine; collects and maintains a look-up list of all the declared identifiers (variables), and enforces a strict set of rules as to how these are accessible to currently executing code.
This got me confused. How is javascript “compiled”? I know it is a interpreted language. Let me show you what I mean.
In C++,
- You write your code in the compiler.
- You let your compiler compile your code, a.k.a turn it into machine code.
- Then you hit run.
As the example gave out above, I have a few questions to ask:
- What is engine? Like chrome V8 engine? And is this engine in the cloud?? Or it is on your local machine, inside of chrome browser.
- Scope, is this scope of “global scope” and “local scope”?
- So the 1st 2 item above, are things you can see, the tools that are needed to compile js, one is the engine, another one is the compiler, which is translating your js code into machine code, and the last one is the set of rules in javascript.
Am I understanding these correctly?