Page 1 of 52 · Getting started · 14 min
What is JavaScript?
JavaScript is the language that makes a web page do something after it has loaded: react to a click, check a form, talk to an API, update a label. The same language also runs outside the browser. Node.js uses it to start test runners, read files, and call HTTP APIs. Playwright, Cypress, and most modern UI automation are JavaScript (or TypeScript that compiles to it). If you are a tester, this is not a “nice extra.” It is the language your failures are written in.
You write source text. A JavaScript engine (V8 in Chrome and Node, SpiderMonkey in Firefox, JavaScriptCore in Safari) parses that text and runs it. You do not compile a binary the way you might in Java. That is why a typo often shows up as a red error at run time, not as a build failure — unless you add TypeScript or a linter, which we cover later.
You do not need the whole language before you write anything. Read a chapter, say the idea out loud, look at the worked example, then keep going. Practice at the end of a chapter is optional typing, not a gate. The goal of this book is that a QA can prepare JavaScript here without bouncing to three other sites for the core.
1Where it runs
In a browser tab, JavaScript can read the document tree (the DOM), listen for clicks and typing, store small bits of data, and call servers with fetch. The page you see is HTML and CSS; JavaScript is the moving part. In Node.js there is no document unless you open a browser from a test. Instead you get files, processes, environment variables, and HTTP clients. Playwright tests run in Node and drive a real browser — two hosts in one job.
The language core is the same in both places: numbers, strings, functions, objects, promises, modules. What changes is the host toolbox. document.querySelector is undefined in a Node spec file. fs.readFile is undefined in a page script. When you see “document is not defined,” you ran browser code in Node. When you see “fs is not defined,” you did the opposite.
Engines implement a standard called ECMAScript (ES2015, ES2020, and so on). People still say “ES6” for the 2015 wave: let/const, arrows, classes, promises, modules. You will use those every day. This book teaches that core first, then the host APIs testers actually touch: fetch, URL, cookies, storage, the DOM.
2How this book is laid out
Chapters are meant to be read in order, like a short book, not like a random wiki. Getting started is the engine and the console. Language basics is values, operators, and conversion — the soil everything else grows in. Data and logic is functions, arrays, objects, and loops. Functions in depth is scope, hoisting, this, and closures: the topics interviewers mean by “do you really know JavaScript?”
Modern JavaScript is modules, JSON, TypeScript-in-one-sitting, and Node/npm so you can open a Playwright repo. Asynchrony is callbacks, timers, promises, the event loop, fetch, URLs, and forms. Browser and problem solving is the DOM, storage, cookies, algorithms, and how to write an assertion that fails usefully.
Each chapter has an intro, headed sections, at least one code sample, a plain-words box, worked examples with printed results, and a short “watch out” list. Practice links take you to the editor if you want to type. You can skip practice until a chapter feels shaky. You should not skip asynchrony.
console.log("Hello, JavaScript");3Mental model
Every program, including a test, is four verbs: store, decide, repeat, package. Variables store. if and === decide. Loops and map repeat. Functions package. Objects and arrays are how you store several things. Promises are “this store will be filled later.” If a page feels abstract, ask those four questions about the example in front of you.
A test is a program that is allowed to fail. It stores a page or a response, decides whether the world matches, and throws when it does not. That is why this book keeps returning to ===, truthiness, and await. Framework docs assume you already have that model.
4How to read this tutorial
Scroll. One heading is one sitting. The sidebar is a jump list, not homework. Arrow keys move to the previous or next chapter. If you only have twenty minutes, finish the current heading, not “the whole of async.”
When you hit a code sample, predict the result before you look at the worked example. Predicting is studying. If you are wrong, read the heading again; do not just copy the snippet into muscle memory.
Do not skip Functions in depth or Asynchrony. Then read JSON, URLs, cookies, Node/npm, and assertions. Those are the chapters people otherwise open MDN for at 11 p.m. before an interview.
5Why QA people learn this language
Playwright, Cypress, WebdriverIO, and most API tools in Node are JavaScript (or TypeScript that compiles to it). When a test is red, the stack is JS: a missed await, a wrong ===, a JSON field that is undefined. Framework docs will not save you if you cannot read that error. This book is the language layer so you do not need three other sites for the core.
6ECMAScript vs the host
The language standard is called ECMAScript (ES2015, ES2020, …). Engines implement it. The host adds extra objects: document in a browser, fs in Node, page in Playwright. When someone says “ES6,” they mean the 2015 wave: let/const, arrows, classes, promises, modules. You will use those every day.
Read the story, then the code, then the result. You do not need to type yet.
The computer runs this one line and writes a message in the developer console (not on the page itself).
console.log("The kettle is on");Result · prints: The kettle is on
Store a number, ask a question, pick a message. This is a whole program in three lines.
const cups = 3;
const message = cups > 1 ? "Make a pot" : "Make a mug";
console.log(message);Result · prints: Make a pot
const and functions work in Node and in the browser. document exists only in the browser.
const n = 2 + 2;
console.log(n);
// document.querySelector("h1") // browser onlyResult · prints: 4
Watch out for
- Mixing up Java and JavaScript — they are unrelated languages.
- Trying to memorize every API before writing a single function. Practice first.
Keep reading
Next page: How JavaScript runs
Scroll down, or use the Next button. Arrow keys also turn the page.