Skip to the workspace
Pebellslearn by building
Introduction to TypeScript  ›  Lesson

TypeScript vs JavaScript

TypeScript vs JavaScript 12 minTypeScript is JavaScript plus type annotations that are checked before the code runs and then removed, so the program that runs is plain JavaScript.

Set up TypeScript and run your first file

TypeScript adds a type-checking step to JavaScript development. Set up Node.js, then install a compiler in a small project so you can see the .ts source become runnable .js.

Already set up? Continue to the lesson

New to coding? Meet the tools and find the terminal
Node.js
Runs the generated JavaScript.
TypeScript compiler (tsc)
Checks type annotations and produces JavaScript.
package.json
Records project information and the installed development tools.

A terminal is a window for commands. Its shell interprets those commands. PATH is the list of folders the shell searches for programs. An editor extension adds editing help; it usually does not install the language itself.

In VS Code, open your project folder, then choose View → Terminal. Type at the cursor in the Terminal panel, not in Output, the source file, or the browser address bar. Our command blocks omit prompt symbols such as $ and >; do not add them.

Official VS Code screenshot: the Terminal tab is selected below the editor, with the PowerShell shell name at the right and a command prompt at the left.
Find the Terminal tab and shell name. Open full-size screenshot (new tab).

The dropdown next to the plus button selects a shell. Choose the shell named in your operating-system instructions below. Available choices depend on what you installed.

Official VS Code screenshot: the arrow beside the terminal plus button opens a list containing PowerShell, Command Prompt, Git Bash and Ubuntu WSL.
Official documentation screenshots by Microsoft, VS Code terminal guide, CC BY 3.0 US. Unmodified; your version may look different.

Choose a system to see its installation steps. A computer is needed for these local setup instructions.

Official documentation and illustrated guides

Instructions reviewed 2026-10-27. Use the linked installer page for current versions and supported operating systems.

Continue to the lesson

typescript / TypeScript vs JavaScript

Explore each scene at your own pace.

01 · The rule

The rule

TypeScript vs JavaScript

TypeScript is JavaScript plus type annotations that are checked before the code runs and then removed, so the program that runs is plain JavaScript.

Separate checks made before execution from behavior that still runs as JavaScript.

You write task.titel instead of task.title. JavaScript says nothing: the page loads, and much later a user sees undefined where a task name should be. TypeScript would have underlined that typo the moment you typed it. That early warning is the whole idea.

The rule

TypeScript is JavaScript plus types, checked first and then erased.

Three parts, three ideas:

  • JavaScript plus types. Every valid JavaScript program is also valid TypeScript syntax. TypeScript adds annotations that say what kind of value something holds.
  • Checked first. Before the code runs, the TypeScript compiler reads those annotations and reports mistakes: a missing property, a number passed where a string belongs, a function called with too few arguments.
  • Then erased. The compiler removes the annotations and writes plain JavaScript. Browsers and Node.js run that output; they never see a type.

Here is the task we will model all course long:

type Task = { id: number; title: string; done: boolean };

function formatTask(task: Task): string {
  return `${task.id}. ${task.title}`;
}

formatTask({ id: 1, title: "Buy milk", done: false }); // fine
formatTask("Buy milk"); // error: a string is not a Task

After compiling, what runs is simply:

function formatTask(task) {
  return `${task.id}. ${task.title}`;
}

The type Task line and every : Task have vanished. So types cost nothing at runtime, and they also protect nothing at runtime: if bad data arrives from a server while the program runs, TypeScript is no longer there to stop it.

Scene 1 of 5
Hover to wake the cannons. Drag to move, or use arrow keys when focused. Press Enter to fire a shot.