Section 1 · First Steps
What JavaScript Is and Where It Runs
10 min3 min readCode playground
Lesson at a glance
Know what JavaScript is, where it runs (the browser and Node.js), how to run your first line of code, and what you will build in this course.
No video here — just the real thing: a written lesson, runnable examples, a quiz and practice.
Every website you used today ran JavaScript. When a “Like” counter goes up without the page reloading, when a form tells you your password is too short before you press Send, when a map scrolls under your finger, that is JavaScript running inside your browser. It is the only programming language every browser understands, which is why it is the best first language for anyone who wants to build for the web.
You are going to learn it the slow, solid way: by watching what the computer actually does with each line you write.
One language, two homes
JavaScript is a language: a set of rules for writing instructions. Something has to read those instructions and carry them out. That something is a JavaScript engine. Chrome and Edge use one called V8, Firefox uses SpiderMonkey, Safari uses JavaScriptCore. They all follow the same official standard, called ECMAScript, which gets a new edition every year.
An engine never runs alone. It lives inside a host that gives your code extra abilities:
- In the browser, the host adds the page itself (
document), clicks and key presses, the network (fetch) and a little storage (localStorage). - In Node.js, the same V8 engine runs on a computer or server with no page at all. Instead, the host adds files, servers and command-line tools.
That split matters from day one. Everything in sections 1 to 3 of this course is the language itself, so it works in both places. Section 4 uses browser extras, so that code only runs on a web page.
Your first line of code
Here is a complete JavaScript program. Press Run.
console.log("Pocket is running");
console.log(450 + 1200);Two things happened, in order. First the engine read line 1, saw an instruction to log some text, and printed it. Then it read line 2, worked out 450 + 1200, and printed the result, 1650. Each of these lines is a statement, one instruction, usually ended with a semicolon. The engine runs statements top to bottom, one at a time, and finishes each before starting the next.
console.log() is how you see inside your program. You will use it constantly, and professional developers do too. Anything between the parentheses is worked out first, and the result is printed.
What you will build: Pocket
Throughout this course you build one program, a little at a time: Pocket, an expense tracker. In the next lessons it is a handful of variables printed to the console. By section 3 it holds a list of expenses, totals them by category and sorts them. In section 4 it becomes a web page with a form, a live list and saved data. In section 5 you organise it the way real projects are organised, with modules, classes and proper error handling.
Most lessons end with an exercise. You write code in the editor, press Check, and a set of automatic checks tells you what works and what does not yet. Getting a check wrong is normal and useful: read the message, change one thing, and try again. That loop of write, run, read and fix is what programming feels like every day.
Next you meet the raw material every program works with: values, their types, and the variables that hold them.
Key takeaways
- JavaScript is a programming language that every web browser can run, and Node.js runs the same language outside the browser.
- The language itself is small; the host it runs in (browser or Node.js) adds extras such as the page, files or the network.
- Code runs one statement at a time, top to bottom, unless you tell it to do otherwise.
console.log()prints a value so you can see what your program is doing; it is the first debugging tool you reach for.