Lesson 2: Where Does JavaScript Run?

Overview

One of the most powerful features of JavaScript is that it doesn’t require you to install any complicated software to use it. You already have everything you need: a web browser.

JavaScript runs directly in the browser, making it incredibly accessible to new programmers. You write your code, the browser reads it, and it runs instantly.


The Browser as a JavaScript Environment

Every modern web browser (Chrome, Firefox, Safari, Edge) includes a built-in JavaScript engine that:

  • Reads JavaScript code
  • Executes it line by line
  • Interacts with the web page (DOM)

This is how websites become dynamic and interactive.


What is a JavaScript Engine?

A JavaScript engine is a program inside your browser that takes your JavaScript code and runs it.

Here are a few popular engines:

BrowserJavaScript Engine
ChromeV8
FirefoxSpiderMonkey
SafariJavaScriptCore
Edge (Chromium)V8

💡 These engines are highly optimized and allow JavaScript to run extremely fast — in fact, entire applications are built with just JavaScript.


What Happens When You Load a Web Page?

Here’s a simplified version of what happens:

  1. You open a webpage in your browser.
  2. The browser downloads the HTML, CSS, and JavaScript.
  3. The JavaScript engine starts reading and executing the JavaScript code.
  4. It runs commands like:
    • Showing alerts
    • Changing styles
    • Responding to clicks or typing
    • Fetching data from the internet

So in short: JavaScript runs inside your browser while you’re viewing a webpage.


What About Node.js?

While JavaScript originally only ran in browsers, today it can also run outside the browser thanks to Node.js.

EnvironmentDescription
BrowserRuns JS to create dynamic websites
Node.jsRuns JS on servers and your computer (outside a browser)

Node.js lets developers use JavaScript for backend development, building servers, scripts, APIs, and more.

⚠️ In this beginner course, we focus on JavaScript in the browser. Node.js comes later once you’ve mastered the basics.


Summary

ConceptExplanation
Browser EnvironmentWhere JavaScript runs by default
JavaScript EngineProgram inside the browser that executes JS code
V8, SpiderMonkeyExamples of engines in Chrome and Firefox
Node.jsA tool that runs JavaScript outside the browser
Why it mattersKnowing where JavaScript runs helps you understand how your code interacts with the web

Key Takeaways for Beginners

  • You don’t need to install anything to start learning JavaScript — just open your browser.
  • The browser has everything built in to run JavaScript.
  • In this course, you’ll write and test all your code using your web browser.