Click on a topic to expand and learn in detail.
let message: string = "Hello, TypeScript!";
console.log(message);
TypeScript adds type safety to JavaScript and helps catch errors at compile time.
let name: string = "Alice";
let age: number = 25;
let isStudent: boolean = true;
TypeScript variables have explicit types.
function add(a: number, b: number): number {
return a + b;
}
console.log(add(5,3));
Functions can have typed parameters and return types.
class Person {
name: string;
age: number;
constructor(name: string, age: number) {
this.name = name;
this.age = age;
}
greet() {
console.log("Hello " + this.name);
}
}
let p = new Person("Alice", 25);
p.greet();
TypeScript supports classes, inheritance, and object-oriented programming.