The Browser
When you write Javascript, how does the browser understand what’s been written?
Well, this is handle by a javascript engine and different browsers have different javascript engine
Lets focus on the most popular browser or should i say my favourite browser, Google Chrome.
V8 engine
Google Chrome uses the javascript engine called v8 engine.
“So what’s the purpose of the v8 engine , you may ask ,well the same purpose like any other javascript engine , that is to convert javascript code to binary so that the computer can understand .
Components of the V8 engine
The engine consists of two main components :
Memory Heap — this is where the memory allocation happens
Call Stack — this is to keep track of where we are in the code execution
How do we get to machine code ?
To get to machine code , your javascript file will either have to be compiled or interpeted .
Compilation — the entire source code is converted into machine code at once.
Interpretation — in interpretation , there is an interpreter which runs through the source code and executes it line by line.
Is Javascript compiled or interpreted ?
Javascript used to be a purely interpreted language but the problem with interpreted languages is that they are much, much slower than compiled languages.
Modern Javascript engine now uses a mix between compilation and interpretation which is called just -in-time(JIT) compilation.