Javascript Beyond Basics
Learning the depth of Javascript
JS Engine Internals (V8) + Optimization Magic
What happens when you write:
const x = 5 + 3;It’s not just magically calculated. Here’s what happens:
Breakdown of JS Engine (like V8)
- Parsing
- Converts your code → an Abstract Syntax Tree (AST)
- Detects syntax errors
- Uses a parser (like
Acorn,Esprima)
2. Compilation (not interpretation!)
- Modern JS engines compile JS to machine code
- Uses Just-In-Time (JIT) compilation
- First: Ignition → bytecode
- Then: TurboFan → optimized native code
Get Prince Kumar Chaurasia’s stories in your inbox
Join Medium for free to get updates from this writer.
3. Execution
- Your code runs in bytecode/natively optimized machine instructions
4. Optimization
- V8 watches how your code behaves
- If a function runs often with the same type of data → it optimizes
- If behavior changes (e.g., types flip) → it de-optimizes!
V8 Pipeline
Source Code → Parser → AST
↓
Interpreter (Ignition) → Bytecode
↓
Profiler watches for "hot code"
↓
Optimizing Compiler (TurboFan) → Native Machine CodeInline Caching
JS is dynamic, but V8 assumes things stay the same for speed.
function greet(user) {
return "Hello " + user.name;
}V8 caches the user.name lookup. If later you change the object’s shape — it has to throw away that optimization.


![Infinite Scroll using React & JavaScript — [Asked in Machine Coding Rounds of Big Tech Companies]](https://miro.medium.com/v2/resize:fit:1358/format:webp/1*hIqA_3mkWt9CLmJ4JXOGYw.jpeg)






