Module 0 · What JavaScript Is, Where It Runs, and How an Engine Runs It
Where It Runs: Browser, Server, Phone, Desktop
In this lesson
- Name the four places JavaScript runs, with one real product in each.
- Explain what stays the same in all four places and what changes.
- Describe what Node.js is, and what the Playground can and cannot do.
Kenji has read three blog posts and is worried. One says "learn frontend JavaScript", one says "learn backend JavaScript", and one says "learn React Native". He wants to know which JavaScript to learn first.
The honest answer is that there is only one. The same language runs in a browser, on a server, inside a phone app and inside a desktop app. What changes is the room it runs in, and what it is allowed to touch there.
This lesson shows the four rooms. Then it runs one program in two of them and gets the same output, which is the whole argument in one picture.
One language, four places
An engine is the program that reads JavaScript and runs it. Lesson 04 opens one up. For now, think of the engine as a box that runs the language, and nothing else. It cannot draw a page, read a file or open a network connection on its own.
A runtime is an engine plugged into a place, plus the extra tools that place offers. The browser is one runtime, and Node.js is another. The language inside is the same; the extra tools are not.
So "frontend JavaScript" and "backend JavaScript" are the same language in two different rooms.
The browser: JavaScript next to a page
Every browser has an engine inside it. When a website sends JavaScript, the browser runs it right beside the page you are looking at. That is how a "Like" button turns blue without the whole page reloading.
The browser's extras are the things a page needs. The most important one is document, which is the page itself, ready to be read and changed. Another is window, the browser tab around it. You will use both in Module 14, in a safe sandbox inside the lesson.
What the browser does not give you is just as important. A web page cannot read the files on your laptop on its own. That limit protects you from every website you have ever opened.
So in a browser, JavaScript can touch the page and cannot touch your files.
The server: Node.js
In 2009 a programmer named Ryan Dahl took V8, the engine from Google Chrome, and ran it outside the browser. He added the tools a server needs: reading and writing files, talking over the network, starting other programs. He called the result Node.js, usually shortened to Node.
Node is not a new language. It is the same JavaScript with different extras. Instead of document it has fs, the file system module, and process, the running program itself. Module 1 uses fs in the starter code that reads your input.
Big companies run real traffic on it. In 2013 PayPal rebuilt one of its busiest pages, the account overview, twice: once in Java and once in Node. Its engineering blog reported that the Node version was built almost twice as fast by fewer people, and cut the average response time by 35%.
So Node is V8 outside the browser, with files and a network instead of a page.
The phone and the desktop
The phone. React Native, made at Facebook (now Meta), lets JavaScript control a real phone app. The buttons and lists are the phone's own native ones, not a web page. Meta uses it in parts of the Facebook and Instagram apps, and Instagram's engineers have written about moving screens to it.
The desktop. Electron packs a browser engine and Node together into a desktop program. VS Code, the code editor many programmers use every day, is built on Electron. So is Discord's desktop app.
Neither of these is the first thing to learn. Both take ordinary JavaScript and put it in a new socket, which is why this track teaches the language first.
The same program in two consoles
A console is a text window where a program's printed lines appear. A browser has one hidden inside it, and Node prints to the terminal (the text window where you type commands). Lesson 05 shows you how to open both.
A small function that works out the area of a rectangle, then prints one line. Module 5 explains functions properly; here, read it as "a named recipe that gives back an answer".
function area(width, height) {
return width * height;
}
console.log("Area: " + area(4, 5));
Area: 20
The two figures below show the same five lines run in Chrome's console and in Node. The answer is the same in both.
Run in Compilerundefined is the console reporting that the last line gave back no value; lesson 05 explains it.The difference shows up only when a program reaches for a room's extras. Example 2 asks each room what it has.
typeof asks what kind of thing a name holds. Module 1 covers it fully. Here it answers a simpler question: does this room have a page, a tab and a running process?
console.log(typeof document, typeof window, typeof process);
undefined undefined object
That is Node's answer, and the Playground's: no page, no tab, but a process. Paste the same line into a browser console and you get object object undefined, the exact opposite.
Two things a browser does not have: the file system module and the process.
const fs = require("fs");
console.log(typeof fs.readFileSync);
console.log(process.platform);
console.log(process.version.startsWith("v22"));
function
linux
true
readFileSync reads a whole file, and Module 1's starter uses it to read your input. The Playground runs on Linux, so line 2 says linux; on a Windows laptop it says win32. Line 3 confirms the Node version is 22.
The Playground: Node.js 22 in a box
Every Run button in this track sends your code to the Progsity Playground. Here is exactly what it is, so you never have to guess.
- It is Node.js 22. Your code is saved as a file called
main.jsand run with thenodecommand, inside a sandbox (a locked box with time and memory limits). - It has stdin and stdout. stdin (standard input) is the text you type into the Input box before you press Run. stdout (standard output) is everything your program prints.
- It has no page. There is no
documentand nowindow, as Example 2 showed. The browser lessons of Module 14 run in a separate sandbox inside the lesson. - It has no internet. A program that tries to download something fails, as mistake 2 below shows.
The judged problems of this track run in the same box. That is why every problem reads its input from stdin and prints its answer, and never touches a page.
So the Playground is Node 22 with input and output, and nothing else.
Where this is used
- The browser. Every website you open runs JavaScript in its pages. In Google Maps, it redraws the map as you drag it, without reloading the page.
- The server: Netflix and PayPal. Netflix serves its website's pages from Node. PayPal moved its account overview page to Node in 2013 and published the speed-up described above.
- The phone: React Native. Parts of Meta's Facebook and Instagram apps are written in JavaScript with React Native, drawing the phone's own native screens.
- The desktop: Electron. VS Code and Discord's desktop app are JavaScript programs wrapped in Electron, so one codebase runs on Windows, macOS and Linux.
Common mistakes
1. Reaching for the page on the Playground.
const title = document.querySelector("h1");
console.log(title);
Node.js 22 stops on line 1: ReferenceError: document is not defined. There is no page in Node, so there is nothing called document. You will make this mistake after copying browser code from a tutorial. Run page code in a browser, and run judged problems with stdin.
2. Expecting the Playground to reach the internet.
fetch("https://example.com").then((response) => console.log(response.status));
On the Playground this ends in TypeError: fetch failed, with getaddrinfo EAI_AGAIN example.com as its cause: the box could not even look up the address. On your own machine the same line prints 200. The sandbox has no network on purpose, so a judged program cannot fetch its answers.
3. Believing frontend and backend JavaScript are two languages.
No error tells you this; you just learn the same things twice. Example 1 printed the same line in a browser and in Node. Learn the language once, then learn each room's extras when you need them.
4. Calling Node.js a language or a framework.
Node is a runtime: an engine plus tools. Saying "I know Node but not JavaScript" makes no sense in an interview. Say "I write JavaScript, and I use Node on the server."
Run Example 1 with its Run link. Then change area(4, 5) to area(7, 3) and run it again.
Check yourself. The second run prints Area: 21. If you get Area: 20 again, the change was not saved before you pressed Run.
Fill in a small table with four rows, one for each room: the browser, Node, React Native and Electron. Give each row two columns: "can touch the page" and "can read files".
Rules. Answer from this lesson only, with yes or no. Add one real product to each row.
Check yourself. The browser row is "yes, no". The Node row is "no, yes". Electron carries both a browser engine and Node, so think about what that gives it. React Native draws native screens, not a web page.
A friend wants to solve a judged problem by reading the input from a text box on a web page, with document.querySelector. Explain in three sentences why that cannot work on this track, and what the program should read instead.
Check yourself. A good answer names the room the judge runs in, the error the friend would see, and stdin. Module 1's lesson 05 shows the exact lines that read stdin.
Common doubts
Is Node.js a programming language?
No. Node is a runtime: the V8 engine plus tools for files, the network and processes. The language you write in Node is JavaScript.
Should I choose frontend or backend right now?
Not yet. Both need the same language, and that is what Modules 1 to 13 teach. Module 14 then opens the browser's extras, and you can choose with real experience behind you.
What are Deno and Bun?
Two newer runtimes, like Node. Deno was started by Node's own creator and also uses V8. Bun uses JavaScriptCore, Safari's engine. Your JavaScript runs in all three.
If a phone app is written in JavaScript, is it just a website?
Not with React Native. The JavaScript decides what to show, but the buttons and lists are the phone's own native parts. That is why such apps feel like ordinary phone apps.
Why do people say Electron apps are heavy?
Each Electron app carries its own copy of a browser engine, so it downloads larger and uses more memory than a native app. VS Code shows that careful work keeps one fast anyway.
Key takeaways
- JavaScript runs in four places: the browser, the server (Node.js), the phone (React Native) and the desktop (Electron).
- The language is the same everywhere, and an engine runs it in each place; what changes is what each place lets the code touch.
- The browser has the page (
document,window); Node has files and the process (fs,process). - Node.js is the V8 engine run outside the browser, made by Ryan Dahl in 2009.
- The Playground is Node.js 22 in a sandbox: stdin in, stdout out, no page and no internet.
Next, a different kind of question: what JavaScript can do for your career, with numbers and their sources.
End of lesson 2
Mark it done, and your progress moves with you.
Next: The Job Market, Honestly: What JavaScript Gets You and What It Does Not