Learn Programming, Tech & Coding · Free Online Tools

IT Question Answer
Back to What Is
What is TypeScript and Why Use It?

What is TypeScript and Why Use It?

What Is410 viewsBy Admin
typescript

What is TypeScript?

TypeScript is a superset of JavaScript created by Microsoft that adds static typing. You write TypeScript, the compiler checks your types, and it compiles down to plain JavaScript that runs anywhere JS runs.

The Core Idea

// JavaScript — error only appears at runtime
function add(a, b) { return a + b; }
add(5, "10"); // "510" 😬

// TypeScript — error caught before you even run it
function add(a: number, b: number): number { return a + b; }
add(5, "10"); // ❌ Compile error: string not assignable to number

Why Teams Adopt TypeScript

  • Catch bugs early — type errors surface in your editor, not in production.
  • Better autocomplete — your IDE knows the shape of every object.
  • Safer refactoring — rename a field and TS shows every place that breaks.
  • Self-documenting — types describe what functions expect and return.

Basic Types

let isDone: boolean = false;
let age: number = 30;
let name: string = "Sara";
let list: number[] = [1, 2, 3];
let tuple: [string, number] = ["x", 1];

interface User {
  id: number;
  email: string;
  isAdmin?: boolean; // optional
}

FAQs

Is TypeScript worth it for small projects?

For tiny scripts, maybe not. For anything with multiple files or a team, the safety and tooling pay off quickly.

Do browsers run TypeScript?

No — it compiles to JavaScript first via tsc or a bundler. Read more in our TypeScript guides.