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 info N nikitamehrotra99 Follow Improve Article Tags : TypeScript Geeks Premier League 2023 Explore TypeScript Tutorial 8 min read TypeScript BasicsIntroduction to TypeScript 3 min read Difference between TypeScript and JavaScript 4 min read How to install TypeScript ? 3 min read Hello World in TypeScript 2 min read How to execute TypeScript file using command line? 2 min read Variables in TypeScript 6 min read What are the different keywords to declare variables in TypeScript ? 4 min read Identifiers and Keywords in TypeScript 2 min read TypeScript primitive typesData types in TypeScript 3 min read TypeScript Numbers 4 min read TypeScript String 4 min read Explain the concept of null and its uses in TypeScript 3 min read TypeScript Object typesWhat are TypeScript Interfaces? 4 min read TypeScript class 4 min read How enums works in TypeScript ? 4 min read TypeScript Tuples 4 min read TypeScript other typesWhat is any type, and when to use it in TypeScript ? 3 min read How to Create an Object in TypeScript? 4 min read What is an unknown type and when to use it in TypeScript ? 3 min read Explain the purpose of never type in TypeScript 3 min read TypeScript combining typesTypeScript Union 3 min read What are type aliases and how to create it in Typescript ? 3 min read TypeScript AssertionsExplain Type assertions in TypeScript 3 min read TypeScript FunctionsHow to write a function in Typescript ? 4 min read How to achieve function overloading in TypeScript ? 2 min read Explain the arrow function syntax in TypeScript 2 min read TypeScript toPrecision() Function 1 min read TypeScript toFixed() Function 2 min read TypeScript toLocaleString() Function 2 min read TypeScript toString() 1 min read TypeScript interfaces and aliasesWhat are TypeScript Interfaces? 4 min read What are type aliases and how to create it in Typescript ? 3 min read TypeScript classesHow to Extend an Interface from a class in TypeScript ? 2 min read How to Create an Object in TypeScript? 4 min read How to use getters/setters in TypeScript ? 5 min read TypeScript Inheritance 3 min read When to use interfaces and when to use classes in TypeScript ? 4 min read Generics Interface in typescript 5 min read How to use property decorators in TypeScript ? 4 min read Like