TypeScript null and undefined Type Last Updated : 28 Apr, 2025 Comments Improve Suggest changes Like Article Like Report TypeScript, a popular programming language, is widely used for building scalable and robust applications. In this article, we’ll explore the null and undefined types, which represent the absence of a value or uninitialized variables. Null TypeWhat is Null?null represents the intentional absence of any object value.It’s often used to signify that a variable or object property does not reference any valid object or value.Example of Null in TypeScript: In this example, we will create a function of gfg, that will accept string or null values and then print the result post-narrowing JavaScript function greet(name: string | null): void { if (name === null) { console.log("Hello, Guest!"); } else { console.log(`Hello, ${name.toUpperCase()}!`); } } greet("GeeksforGeeks"); // Output: Hello, GEEKSFORGEEKS greet(null); // Output: Hello, Guest! Output: [LOG]: "Hello, GEEKSFORGEEKS!" [LOG]: "Hello, Guest!" Undefined TypeWhat is Undefined?undefined indicates that a variable has been declared but hasn’t been assigned any value.It’s commonly used to represent missing function arguments or uninitialized object properties.Example: When strictNullChecks is turned off (which is the default behavior), TypeScript is more permissive with null and undefined, and they are treated as assignable to all types. This means you can assign null and undefined to any variable JavaScript let myVar: string = undefined; let anotherVar: number = undefined; console.log(myVar); // Output: undefined console.log(anotherVar); // Output: undefined Output: undefinedundefinedStrict Null ChecksBy default, TypeScript is more permissive with null and undefined. However, when the strictNullChecks option is enabled, variables and properties must be explicitly typed as either nullable or non-nullable. Comment More infoAdvertise with us Next Article TypeScript null and undefined Type N nikitamehrotra99 Follow Improve Article Tags : JavaScript Web Technologies Geeks Premier League TypeScript Geeks Premier League 2023 +1 More Similar Reads How to check null and undefined in TypeScript ? In this article let's learn how to check if a variable is null or undefined in TypeScript. A variable is undefined when it's not assigned any value after being declared. Null refers to a value that is either empty or doesn't exist. null means no value. To make a variable null we must assign null val 3 min read Data types in TypeScript In TypeScript, a data type defines the kind of values a variable can hold, ensuring type safety and enhancing code clarity.Primitive Types: Basic types like number, string, boolean, null, undefined, and symbol.Object Types: Complex structures including arrays, classes, interfaces, and functions.Prim 3 min read TypeScript Return type void The void type in TypeScript represents the absence of a return value for functions. It indicates that a function does not return any value, ensuring that the function's purpose is solely to act without returning data.Syntaxfunction functionName(parameters: ParameterType): void { // Function body // 2 min read TypeScript strictNullChecks on Type TypeScript's strictNullChecks feature enforces type safety by treating null and undefined as distinct types. When enabled, it ensures variables cannot be assigned these values unless explicitly allowed, preventing runtime errors and enhancing code reliability and readability.Enabling strictNullCheck 3 min read Undefined in JavaScript Undefined is a type of Data type in JavaScript. It is a primitive value undefined, when a variable is declared and not initialized or not assigned with any value. By default, the variable was stored with an Undefined value. Undefined is a global read-only variable that represents the value Undefined 2 min read Like