Tsallaka zuwa abun ciki
Justice Tech School

Basic Types

Basic types are string, number, boolean, null, undefined, bigint and symbol. TypeScript often infers the type for you, so you only annotate when needed. Avoid any because it switches checking off; unknown is the safe alternative.

Example
let age: number = 21;
let name = "Ada";
let ok: boolean = true;
console.log(typeof age, typeof name, typeof ok);
let anything: unknown = "text";
if (typeof anything === "string") {
  console.log(anything.toUpperCase());
}

Result

number string boolean
TEXT

Exercise

Which type is safer than any?

let x:  = 5;

Quiz Test

What is type inference?

These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.