null & undefined
TS · Basic Typessyntax
let varName: null = null;
let varName: undefined = undefined;
let varName: string | null = null;example
let resetValue: null = null;
let notAssigned: undefined = undefined;
// Practical usage — nullable types
let selectedUserId: string | null = null;
selectedUserId = "usr_482";output
// selectedUserId can hold either a string or nullNote With strictNullChecks enabled (recommended), null and undefined are NOT assignable to other types unless you explicitly include them in a union. This catches a huge class of runtime bugs.