Quick answer: TypeScript is a typed superset of JavaScript that lets you define the shape of your data, catch bugs while you write code, and compile to plain JavaScript that runs anywhere. This complete beginner’s guide walks you from installation to interfaces, arrays, functions and loops – with hands-on examples you can copy and run today.

What is TypeScript and why does it matter?

TypeScript started life at Microsoft in 2012 as a practical answer to a growing problem: JavaScript is flexible, but that flexibility becomes dangerous as codebases grow. TypeScript adds static types – you tell the compiler what kind of data each variable, parameter and return value should be, and the compiler checks your work before your program ever runs.

The result is code that is easier to read, easier to refactor and dramatically less likely to blow up in production. It is why Angular is built entirely with TypeScript, why React and Vue teams adopt it enthusiastically, and why Node.js backend projects are increasingly written in it. If you want to work in modern web development, TypeScript is no longer optional – it is the standard.

What makes TypeScript different from JavaScript?

  • Static typing: declare types for variables, function parameters and return values, so the compiler catches mistakes early.
  • Intelligent autocomplete: your editor knows the shape of your data, so IntelliSense suggests real properties instead of guessing.
  • Early access to modern features: use ES6 and ES7 syntax today and compile it down to JavaScript older browsers understand.
  • Interfaces and types: describe the shape of objects and API responses once, then reuse that contract everywhere.
  • Confident refactoring: rename a property and the compiler instantly shows every place that breaks.

The best part? TypeScript is every bit the same language you already know. Valid JavaScript is valid TypeScript, so you can adopt it one file at a time on an existing project. Our guide on Getting Started with TypeScript runs through the full benefits and the cross-platform installation story.

How to install TypeScript on Windows, Mac or Linux

TypeScript installs the same way on every operating system because it runs on Node.js. First make sure Node is installed, then open your command prompt or terminal and try the compiler:

tsc --version

If that command throws an error, install TypeScript globally with a single command:

npm install -g typescript

Once the install finishes, run tsc --version again and you will see the installed version. From there you are ready to write your first file – a step-by-step walkthrough lives in our First Program in TypeScript guide, which also shows how to compile a .ts file into JavaScript and run it with Node.

Your first TypeScript program: types, variables and output

Every programming journey starts with a hello world, and TypeScript’s version teaches you the core workflow: write, compile, run. Create a file called demo.ts, add a typed variable, then print it:

let name1: string = "John Doe";
console.log(name1);

Compile it to JavaScript and run it:

tsc demo.ts
node demo.js

You just wrote TypeScript, saw the compiler strip the type annotation, and ran the output. Notice how the compiled demo.js looks almost identical – the power of TypeScript is the safety it adds during development, not extra code at runtime.

Functions in TypeScript: type-safe inputs and outputs

Functions are where TypeScript’s typing shines. You declare both the parameter types and the return type, and the compiler guarantees every caller sends the right data. A simple greeting function looks like this:

function greetings(person: string): string {
  return "Hello, " + person;
}

let user = "John Doe";
console.log(greetings(user));

Pass a number or forget the return type and TypeScript flags it immediately. For a deeper dive into optional parameters, default values and the void return type, see our tutorial on Functions in TypeScript.

Interfaces: describing the shape of your data

An interface is a contract that describes what an object must look like. Instead of hoping an API response has the right fields, you define the shape once and let the compiler enforce it:

interface Students {
  firstName: string;
  lastName: string;
}

function greetings1(students: Students): string {
  return "Hello, " + students.firstName + " " + students.lastName;
}

let person = { firstName: "John", lastName: "Doe" };
console.log(greetings1(person));

Interfaces power APIs, configuration objects and class contracts – and they disappear entirely at runtime, leaving zero overhead. Learn the practical details, including how interfaces differ from type aliases, in our guide to Interfaces in TypeScript.

Arrays and loops: working with collections

Real programs deal with lists, and TypeScript makes arrays type-safe. Create an array of objects, then loop through it to print every record or just one field:

let student_List = 
[ { name:'John', id:12345, class:'Bio' }, { name:'Peter', id:12346, class:'Bio' }, { name:'Adam', id:12347, class:'IT' } ]; for (let x of student_List) { console.log(x.name); }

The for...of loop walks through values directly, while a classic indexed for loop gives you the position of each item. Both approaches are covered in our guide on using a for loop to print an array, and the details of building and printing collections live in our tutorial on creating and printing arrays.

What you should learn next in TypeScript

You now have the complete beginner loop: install, first program, functions, interfaces, arrays and loops. Every one of these concepts builds on the previous one, so treat them as a path:

  1. Getting Started with TypeScript – install and understand the language.
  2. Your First Program – compile and run your first file.
  3. Arrays – store and print collections of data.
  4. Functions – build reusable, type-safe logic.
  5. Interfaces – define contracts for your data.
  6. Loops – iterate over everything efficiently.

From here, you can confidently move into building a real project. If you are just mapping out your whole learning journey, start with our Web Development Roadmap to see exactly where TypeScript fits, and check out our TypeScript tutorials whenever you want to drill into a specific topic.

Frequently asked questions

TypeScript for Beginners is a living guide; bookmark it and revisit each section as you level up.

Is TypeScript hard to learn?

If you know JavaScript, TypeScript is gentle. You start with types on variables and functions, and everything else behaves exactly like JavaScript.

Do I need TypeScript for React or Angular?

Angular requires TypeScript. React and Vue both support it and most professional teams use it because it catches bugs early and improves autocomplete.

Does TypeScript run in the browser?

No. TypeScript compiles to plain JavaScript, and the compiled JavaScript runs in the browser, in Node.js or anywhere JavaScript runs.

How long does it take to learn TypeScript?

A developer who knows JavaScript can learn the core concepts in a few days and become productive in a few weeks of practice.

Will TypeScript slow down my code?

No. Types are erased during compilation, so the JavaScript you ship is essentially identical to what you would have written by hand.