Problem Statement
Explain all core built-in types (string, number, boolean, bigint, symbol, null, undefined, void, never, unknown, any) with a one-line example each.
Explanation
string — text: `const s: string = 'hello'`. number — numeric: `const n: number = 3.14`. boolean — truthy flag: `const ok: boolean = true`. bigint — large integers: `const big: bigint = 9007199254740993n`. symbol — unique key: `const id: symbol = Symbol('id')`. null — intentional emptiness: `let name: string | null = null`. undefined — not assigned yet: `let x: number | undefined`. void — no useful return: `function log(): void {}`. never — cannot return: `function fail(): never { throw Error('x') }`. unknown — must narrow: `let v: unknown; if (typeof v === 'string') v.toUpperCase()`. any — opt-out of checks: `let loose: any = 123; loose.foo()`.
Code Solution
SolutionRead Only
const s: string = 'hi';
const n: number = 42;
const b: boolean = false;
const big: bigint = 1n;
const sym: symbol = Symbol('k');
let maybeName: string | null = null;
let notSet: number | undefined;
function log(): void {}
function boom(): never { throw new Error('nope'); }
let u: unknown = JSON.parse('{"x":1}');
let a: any = 'loose'; a.nonExistent();