8

In Node.js website, they say Node.js is a JavaScript runtime.

Are web browsers like Chrome, Firefox, Edge, ... JavaScript runtimes?

I thought of course, web browser is JS runtime. But I'm confused, In this video 12:10~ He says Web browser is not just JavaScript runtime because it can do more things at one time, it can give us other things.

But I think V8 engine only can do one thing at one time, while JS runtime can do more things than one at one time.

Am I wrong?

7
  • 2
    Web browsers usually include a JS Engine. Commented Aug 1, 2018 at 2:33
  • JS code (i.e. the stuff you write and the libraries you use etc) only does one thing at a time, this is also true in nodejs!! ... However, the underlying JS engine is not restricted in this way - which is how "asynchronous" methods can work Commented Aug 1, 2018 at 2:34
  • @JaromandaX Hmm, I thought engines WERE single-threaded. Or else you're using the term "at a time" in a slightly non-intuitive way. Commented Aug 1, 2018 at 4:26
  • "I thought of course, web browser is JS runtime." I can't imagine why you would have "of course" thought that. Who did you think is painting the pixels on the screen? Commented Aug 1, 2018 at 4:31
  • 1
    engines threadedness has no bearing on how javascript is "processed" by the engine ... javascript code is not "any threaded" - it's ... well developer.mozilla.org/en-US/docs/Web/JavaScript/EventLoop Commented Aug 1, 2018 at 5:14

3 Answers 3

7

A browser contains a Javascript engine (for example Chrome v8). The engine implements a Javascript runtime, which includes the call stack, heap and event loop. The browser also usually includes a set of APIs that augment the Javascript runtime and make asynchronous code execution possible. NodeJS also implements a Javascript runtime using Chrome's v8 engine as well as the Libuv library (event loop and worker threads).

Here's a good video that breaks this all down: https://www.youtube.com/watch?v=4xsvn6VUTwQ

Sign up to request clarification or add additional context in comments.

1 Comment

Does JavaScript engine include event loop? This guys is saying that V8 source code doesn't contain event loop. youtube.com/watch?v=8aGhZQkoFbQ&t=466s
2

They are right, a JavaScript runtime just executes the JavaScript code.

All Web browsers include a JavaScript runtime engine(RE) that executes js code for them but they also have other plugins like java or flash, as well as an html/dom parser and renderers that are not part of the RE, even if those modules were written in JavaScript it does not mean they would be part of the RE.

3 Comments

You are probably confusing runtime and Engine. You can have several runtimes ran by the same engine, in concurrence. Also, all browsers don't have a js engine (and hence won't start any js runtime), e.g Lynx doesn't.
@Kalido In what kinds of scenarios would one engine have multiple runtimes? Are you talking about web workers? Or iframes?
@torazaburo I guess it depends on the implementations, but IIRC in FF a new tab will create a new run-time. Workers would too, for iframe I don't think so.
0

Summary

  1. V8 executes JavaScript code and part of the JS runtime.

  2. The JavaScript runtime adds Web APIs and async handling

    JavaScript runtime= V8 + Web APIs (via Blink) + Event Loop + Call-back Queue

  3. The browser environment includes both of these, plus everything else a browser needs to function

A browser are not merely as a JavaScript runtime; it constitutes a comprehensive web platform that encompasses a JavaScript runtime environment along with numerous other elements.

V8 is purely the JavaScript engine responsible for parsing, compiling, and running JavaScript code .

The event loop is managed by the browser environment (like Chrome's Blink) or by libuv in Node.js (a C library for asynchronous I/O operations and event handling).

In Chrome, the JavaScript engine, called V8, is responsible for parsing, compiling, and executing JavaScript code. However, it only handles the core JavaScript language itself.

Surrounding V8 is the JavaScript runtime environment, which includes V8 along with additional browser-provided features like Web APIs (through Blink), the event loop, and the callback queue. These runtime components allow JavaScript code to perform tasks such as making network requests, setting timers, or interacting with the browser window. Essentially, V8 runs the JavaScript code, while the runtime provides the tools and infrastructure to handle asynchronous operations and external interactions.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.