Basic Types (string, number, boolean)
TypeScript adds types to JavaScript. Types tell the computer what kind of data a variable holds, catching mistakes before your code runs. Think of types like labels on containers: "this box holds numbers" prevents you from accidentally putting text in it.
const name: string = "Daniel"
const age: number = 20
const isActive: boolean = true
const scores: number[] = [95, 87, 92]
// Function with types
function greet(name: string): string {
return `Hello, ${name}!`
}
// Avoid "any": it turns off TypeScript's help
const bad: any = "don't do this"