Labs ICT
⭐ Pro Login

Basics

1 min read | TypeScript Tutorial
⭐

Want the full learning experience?

Get structured courses, certificates, projects, and instructor support with LabsICT Pro.

Explore Pro Courses

Now you're ready to write TypeScript code! The basic syntax looks exactly like JavaScript, but with type annotations. You use `let` for variables that can change, `const` for constants that can't change, and `var` for older function scope (avoid it). TypeScript automatically infers types when you assign values, but you can also explicitly declare types for clarity.

Basic Syntax and Type Inference

Start with simple declarations. When you assign a value, TypeScript can figure out the type (type inference). Use `: type` for explicit annotations. The compiler will catch type mismatches before you even run your code, which is a huge time saver.


let name: string = "Alice";
const age = 25;
let isStudent = false;
let hobbies: string[] = ["reading", "coding"];

// Type inference works automatically
let username = "bob123"; // TypeScript knows this is a string
let score = 100; // TypeScript knows this is a number
let active = true; // TypeScript knows this is a boolean