Search code examples
javascriptv8

Confused about what V8 actually is


I know V8 is a JavaScript engine, but is it also a runtime environment? I know a runtime environment supplies the engine with the event loop, APIs, callback queue etc, but from things I've read it seems that V8 supplies them as well? Is it engine > runtime environment or vice versa?


Solution

  • V8 is a JavaScript engine that provides a runtime environment.

    The JavaScript runtime environment, provided by V8 or any other JavaScript Engine consists of the memory heap, and call stack, where the actual JS code is being compiled and executed.

    The event loop, Web APIs and the callback queue are not provided/supplied by V8, rather they are provided by the environment that V8 is hosted in. The hosting environment for V8 can be the browser (like Google Chrome) or Node.js.

    If you look at this image, on the left side inside the border line, lies the JS runtine environment provided by V8. On the right side, you can see Web APIs, Callback Queue and the Event Loop provided by the browser (the hosting environment). Hope it clarifies.

    Image credits: sessionstack blogpost.

    For further details and clarification, you can have a read about the V8 JS Engine. Plus, this video tutorial is really helpful and exactly addresses your question.