Learn JavaScript – tutorial, cheatsheet & exercises
JavaScript is the language of the web: every browser runs it, and no other language can make web pages interactive directly in the browser. With Node.js (and Deno or Bun), JavaScript also runs on the server, in command-line tools, in desktop apps (Electron), and even on smartphones through frameworks like React Native.
The language is dynamically typed, functional and object-oriented all at once, and it has a few notorious quirks (== vs. ===, this, undefined vs. null). Once you know these pitfalls, you get to work with a huge ecosystem (npm) and a language that evolves every year (ECMAScript). For larger projects, switching to TypeScript is worthwhile later – but the fundamentals are the same.
Hello World in JavaScript
console.log("Hello World!");console.log writes to the console – no main, no class needed.
How to get started with JavaScript
The great thing about JavaScript: you do not need to install anything to get started. Open the developer tools in any browser (F12, or Cmd+Option+I on a Mac) and switch to the "Console" tab – you can type JavaScript there directly.
console.log("Hello from the browser console!");
2 + 3 * 4For real pages, you include a script in an HTML file. defer makes sure the script only runs after the page has been built:
<!DOCTYPE html>
<html lang="de">
<head>
<meta charset="utf-8">
<title>Meine erste Seite</title>
<script src="app.js" defer></script>
</head>
<body>
<h1 id="titel">Hallo</h1>
</body>
</html>For programs outside the browser, install Node.js (LTS version) from nodejs.org – or with brew install node on a Mac or winget install OpenJS.NodeJS.LTS on Windows. Check the installation:
node --version
npm --versionSave console.log("Hello Node!"); as hallo.js and run the file. Without an argument, node starts an interactive console (REPL):
node hallo.js
nodenpm init -y you create a package.json in a folder; from then on you install packages with npm install <name>. Alternatively, Deno and Bun also run JavaScript (and TypeScript) directly.JavaScript learning path
Hello World & console.log
Your first program, comments and output.
Variables & Data Types
let, const, the primitive types and conversions.
Conditions & Comparisons
if, switch, === instead of ==, truthy/falsy and the operators ?? and ?.
Loops
for, for...of, for...in, while, break and continue.
Functions
Declarations, arrow functions, default values and rest parameters.
Arrays, Objects, Map & Set
The most important data structures – and what const really means.
Array Methods: map, filter, reduce
Transforming data functionally – everyday JavaScript.
Destructuring, Spread & Rest
Unpacking, copying and merging values.
Strings, Regex & JSON
Processing text, searching for patterns and exchanging data.
Error Handling
try/catch/finally, custom error classes and typical error types.
Classes & Object-Oriented Programming
class, extends, private fields, getters and prototypes.
DOM & Events in the Browser
Creating and changing elements and reacting to clicks.
Closures, Scope & this
Why functions "take along" their environment and what this really means.
Asynchronous Programming
Event loop, promises, async/await and typical pitfalls.
Iterators & Generators
Making your own collections iterable and producing values lazily.
Modules, npm & Tooling
ES modules, package.json, bundlers and quality tools.
At a glance
More about JavaScript
Test & practice
Interactive quiz, timed exam with certificate, and exercises with an editor: