JSJavaScript

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.

WebsitesWeb appsNode.js serversMobile apps

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 * 4

For 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 --version

Save console.log("Hello Node!"); as hallo.js and run the file. Without an argument, node starts an interactive console (REPL):

node hallo.js
node
TipVisual Studio Code is a good editor. With npm 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.

At a glance

First released1995
CreatorBrendan Eich
ParadigmMulti-paradigm (event-driven, functional, OOP)
TypingDynamic, weak
ExecutionJIT-interpreted (browser, Node.js)
File extension.js

Test & practice

Interactive quiz, timed exam with certificate, and exercises with an editor:

JavaScript compared

Hello World: JavaScript comparedVariables: JavaScript comparedConditionals: JavaScript comparedLoops: JavaScript comparedFunctions: JavaScript comparedLists and Arrays: JavaScript comparedDictionaries and Maps: JavaScript comparedClasses and Objects: JavaScript comparedError Handling: JavaScript comparedReading Files: JavaScript compared