#1 Data Analytics Program in India
₹2,499₹1,499Enroll Now
4 min read
Question 1 of 48easy

What is TypeScript?

Understanding TypeScript and its benefits.

What You'll Learn

  • What TypeScript is
  • Why use TypeScript
  • TypeScript vs JavaScript

What is TypeScript?

TypeScript is a strongly typed superset of JavaScript developed by Microsoft. It compiles to plain JavaScript and adds optional static typing.

Key Benefits

BenefitDescription
Type SafetyCatch errors at compile time
Better IDE SupportAutocomplete, refactoring
Self-DocumentingTypes serve as documentation
ScalabilityEasier to maintain large codebases

Example

code.tsTypeScript
// JavaScript
function greet(name) {
  return "Hello, " + name;
}

// TypeScript
function greet(name: string): string {
  return "Hello, " + name;
}

greet(123); // Error: Argument of type 'number' is not assignable

TypeScript Compiles to JavaScript

code.tsTypeScript
// TypeScript
const add = (a: number, b: number): number => a + b;

// Compiles to JavaScript
const add = (a, b) => a + b;