Every Browser has it’s own JS Engine in their JS Runtime Environment. Node.js has also JS Runtime Environment. For example, Google and Node.js use V8, Mozilla Firefox uses Spider Monkey.
let a = 10 splits into tokens
10, each of them called token. We can call them as,
let => Keyword/Kind.
a => Identifier.
= => Assignment.
10 => Literal.
After generating the Tokens the next task is to make AST or Abstract Syntax Tree. An AST is a tree which generated by tokens. For
let a = 10 the AST will be,
After generating the AST the next phase is Compilation.
V8 engine uses Ignition Interpreter and Turbofan Compiler. Ignition will interpret and Turbofan will compile our JS code.
In execution phase code (interpret and compiled) will go to execute. We have Memory Heap and Garbage Collector in this phase. Every variable, function store in the Memory Heap and after a certain time when the item is not necessary in the Heap the Garbage Collector removes it.