null
A special value meaning no value or no object, set on purpose to show that something is empty or absent.
In more detail
Using null as if it were a real object, such as calling a method on it, crashes the program or throws an error, so code must check for it first. Many type systems let you mark whether a value may be null, as string | null does in TypeScript, which makes absence explicit. In JavaScript, null is distinct from undefined, and typeof null returns "object", a long-standing quirk.
Examples
In the browser: Code must check for null before using a result, or it will throw an error when it reads a property. The optional chaining operator ?. in the examples does that check for you.Java: calling a method on null throws NullPointerException; the course uses Optional for lookups that may find nothing.Related terms
- querySelector() — The DOM method that returns the first element matching a CSS selector, or null if nothing matches.
- Element.closest() — The DOM method that starts at an element and walks up through its ancestors, returning the first one, itself included, that matches a selector.
- validation schema — A description of what valid data looks like, checked by code while the program runs so bad data is rejected at the door.
- expand-and-contract — A way to change a live database in safe steps: add the new structure, move data and code to it, then remove the old structure.
- NullPointerException — The unchecked exception thrown when code uses a null reference as if it pointed to an object.
- Optional — A container that holds either one value or nothing, used as a return type to make "no result" visible to the caller.
- reference type — A type whose variables hold a reference, a pointer to an object stored elsewhere, rather than the value itself.
- garbage collection — The automatic freeing of memory held by objects that the program can no longer reach.
- flowing and paused modes — The two ways a Readable stream delivers data: in flowing mode it pushes chunks as fast as they arrive, in paused mode the consumer pulls them.
- undefined — The JavaScript value meaning not set: a variable with no value yet, a missing property or a function that returned nothing.
- strictNullChecks — The compiler option that makes null and undefined separate types, so you must handle them before using a value.
- nullish coalescing — The double question mark operator (??), which gives a fallback value only when the left side is null or undefined.
- NonNullable<T> — The utility type that removes null and undefined from type T.
Taught in
- Modern DOM Querying: querySelector, closest And matches — Frontend Architecture & Web Platform
- Memory Management: Garbage Collection, Memory Leaks And WeakMap — Frontend Architecture & Web Platform
- End-to-End Type Safety: Shared Schemas & DTOs — Production Full-Stack Engineering
- Database Access & Migrations: ORM & Data Layers — Production Full-Stack Engineering
- End-to-End Testing with Playwright: Multi-Tier Suites — Production Full-Stack Engineering
- Primitive And Reference Types — Modern Java: Virtual Threads & High-Throughput Services
- Sealed Types And Exhaustiveness — Modern Java: Virtual Threads & High-Throughput Services
- Handling Nulls With Optional — Modern Java: Virtual Threads & High-Throughput Services
- Node.js Process Architecture: Memory & Heap Spaces — Node.js Internals & Backend Services
- Stream Mechanics: Readable Streams & Flowing Modes — Node.js Internals & Backend Services
- tsconfig.json: target, lib, strict And NodeNext — Production TypeScript
- any Versus unknown: Defensive Typing In Practice — Production TypeScript
- void, undefined And null: Exact Optional Property Types — Production TypeScript
- Union Types, Intersections And Property Conflicts — Production TypeScript
- Typeof Guards, Truthiness And Equality Narrowing — Production TypeScript
- The in Operator And Instanceof Narrowing — Production TypeScript
- Custom Type Predicates: Functions Returning is Type — Production TypeScript
- Assertion Signatures: asserts condition And Invariants — Production TypeScript
- Default Generic Arguments And Multi-Type Parameters — Production TypeScript
- Union Utilities: Exclude, Extract, NonNullable And Awaited — Production TypeScript