Hackforge Academy

Category: javascript

What and Why TypeScript

Published on 20 Apr 2026

Explanation

TypeScript is a strongly typed superset of JavaScript developed by Microsoft. It adds static typing, interfaces, and modern features to JavaScript and compiles into plain JavaScript that runs in browsers or Node.js.

Code:

let message: string = "Hello TypeScript";
console.log(message);

Explanation

TypeScript helps developers catch errors during development instead of runtime by enforcing type safety.

Code:

let age: number = 25;
// age = "twenty five"; 
// Error: Type 'string' is not
assignable to type 'number'

Explanation

Explicit types make code easier to understand and maintain, especially in large projects.

Code:

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

Explanation

TypeScript provides interfaces, classes, access modifiers, and inheritance for better structured applications.

Code:

interface User {
  name: string;
  age: number;
}

const user: User = {
  name: "Praveen",
  age: 25
};

Explanation

TypeScript improves developer productivity with auto-completion, refactoring, and error detection in editors like VS Code.

Code:

function add(a: number, b: number): number {
  return a + b;
}

Explanation

Frameworks like Angular and enterprise-level applications prefer TypeScript for scalability and maintainability.

Code:

// Example Angular-style TypeScript class
class AppComponent {
  title: string = "My App";
}

πŸš€ Learn Spring Boot with real-world projects

πŸ’‘ Build REST APIs step by step

🧠 Improve backend development skills

🎯 Get career-ready practical training

Join Our Free WhatsApp Community

Direct access to niche-specific mentors and peers on WhatsApp.

🐍

Python Community

Discuss Django, FastAPI, AI integration, and automation scripts with 15k+ developers.

Join Python Community
βš›οΈ

React Community

Master Next.js, Framer Motion, and State Management. Share your latest UI components.

Join React Community
β˜•

Java Community

Deep dives into Spring Boot, Microservices architecture, and high-performance backend ops.

Join Java Community