CodeBlanks Logo Icon CodeBlanks

What is V8?

Learn what the V8 engine is and how it works.

What is V8?

V8 is Google's open-source JavaScript engine. Node.js, Chrome and Electron are built on V8. V8 compiles and executes JavaScript as machine code, which lets code run fast outside the browser.

V8 uses a JIT (just-in-time) compiler: it compiles code at runtime instead of interpreting it. This yields much faster execution than interpreted languages. V8 also handles memory management (garbage collection) and object internals (hidden classes) itself. As a Node.js developer, knowing what V8 does explains why certain patterns are fast. This lesson surveys the core building blocks of V8.

JIT compilation

V8 compiles JavaScript at runtime with JIT instead of interpreting it. Code is first turned into bytecode quickly, then frequently run sections are promoted to machine code. This balances slow interpretation and slow full compilation.

When a function is first called V8 compiles it quickly. Once the call count crosses a threshold V8 marks the function hot and applies more aggressive optimization. Example: function isHot(callCount) { return callCount >= 100; }. A function called 100 times is considered hot. Thanks to JIT, Node.js is not as fast as C but much faster than interpreted languages.

Practice Describe the V8 engine

Write a v8Engine function. Return {name: 'V8', language: 'JavaScript', type: 'JIT'}. Print with console.log(v8Engine().name + ': ' + v8Engine().type).

Starter code

index.js
// Write a function describing the V8 engine
// Return {name: 'V8', language: 'JavaScript', type: 'JIT'}
// Print name and type
// write here

Sample solution

index.js
function v8Engine() {
  return {name: 'V8', language: 'JavaScript', type: 'JIT'};
}
console.log(v8Engine().name + ': ' + v8Engine().type);

Expected output

V8: JIT

Questions and answers

Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.

1 Which engine is Node.js built on?

  • SpiderMonkey
  • Chakra
  • V8 Correct answer
  • JavaScriptCore

Explanation: Node.js is built on the V8 engine.

2 Return the V8 engine type

Question
function v8Engine() { return {name: 'V8', language: 'JavaScript', type: '____'}; }
Answer
function v8Engine() { return {name: 'V8', language: 'JavaScript', type: 'JIT'}; }

Explanation: V8 uses a JIT compiler.

3 Match each concept to its description

Term Meaning
V8 JavaScript engine
JIT Compile at runtime
Node.js Built on V8
Chrome Browser using V8

All lessons in Expert