JavaScript Engine Flashcards
Engine
A JavaScript Engine is a computer program that you give JavaScript code to and it tells the computer how to execute it. Basically a translator for the computer between JavaScript and a language that the computer understands.
Parser
Process of analyzing the source code, checking for errors, and breaking it up into parts.
AST
A tree graph of the source code.
Interpreter
An interpreter directly executes each line of code line by line, without requiring them to be compiled into a machine language program.
Compiler
First it converts the code into a code that the computer can understand, and then it runs the code
e.g. Babel or TypeScript.
JIT Compiler
In modern engines, the interpreter starts reading the code line by line while
the profiler watches for frequently used code and flags then passes is to the compiler to be optimized. In the end, the JavaScript engine takes the bytecode the interpreter outputs and mixes in the optimized code the compiler outputs and then gives that to the computer. This is called “Just in Time” or JIT Compiler.
Differences of using Interpreters and Compilers
Interpreters: Fast to start running, because the code executes right away. Does not optimize code, if you have a function that returns the same result every time, the interpreter does not optimize this code.
Compiler: Slower to start running. Faster when starts running because code can be optimized.
Memory Heap
A place to allocate, use, and remove memory as needed.
Call Stack
Keeps tack of where we are in the code, so we can run the program in order.
Stack Overflow
Happens when you keep calling functions that are nested inside each other. Maximum call stack size exceeded.
Garbage Collection
JavaScript is a garbage collected language. If you allocate memory inside of a function, JavaScript will automatically remove it from the memory heap when the function is done being called.