The null keyword is considered as a data type in TypeScript as well as in JavaScript. The null keyword indicates the unavailability of a value. It can be used to check whether a value is provided to a particular variable.
Example:
function getData(orgName: string | null, orgDesc: string | null): void {
if (orgName === null || orgDesc === null) {
console.log("Not enough values provided to print.");
}
else {
console.log(`Organization Name: ${orgName},
nOrganization Description: ${orgDesc}`);
}
}
getData(null, null);
getData("Test",
"A Computer Science Portal.");
Output:
Not enough values provided to print. Organization Name: Test, Organization Description: A Computer Science Portal.