Simple & Special Types

Simple & Special Types: TypeScript is JavaScript where every variable gets a label attached — like a box marked 'numbers only,' where trying to put the wrong thing in trips a war

TypeScript is JavaScript where every variable gets a label attached — like a box marked 'numbers only,' where trying to put the wrong thing in trips a warning before the box even closes (at compile time). So if simple types like number and string are this intuitive, why is there a whole topic worth learning here? Because the real power isn't in one variable, it's in those simple types propagating consistently through function parameters, return values, and object fields — Java already had this built in from birth with `int`, `String`, `boolean`; TypeScript retrofits that same discipline onto JavaScript, where it was always optional. The QA-relevant difference: in plain JavaScript, passing the string `"25"` as an age into a test helper silently produces wrong math (`"25" + 5` becomes `"255"`); TypeScript code that uses simple types correctly flags that mistake instantly in the IDE, before the test is ever run.

Java requires explicit types: int x = 5; String name = 'Ali'. TypeScript is the same: let x: number = 5; let name: string = 'Ali'. Difference: TypeScript can usually infer the type automatically — you don't have to write it everywhere.

Micro Lab: TypeScript coding practice

Replace the TODO line with the critical line from the expected solution. This is not a real runtime; the goal is to reinforce writing the correct structure in a controlled way.

How the basic type system works

let age: number = 25 — colon specifies type explicitly

let city = 'Istanbul' — TypeScript automatically infers string

let x: any cancels all type safety advantages — avoid in production

Order the best practice steps when defining a variable in TypeScript:

Understand what the variable is for

Choose the most specific type (string, number...)

Skip annotation if inference suffices

Leave a comment if you're forced to use any

When you write let city = 'Istanbul' in TypeScript, what type does TypeScript assign?