1.

Explain the concept of null and its use in TypeScript.

Answer»

In programming, a null value indicates an absence of value. A null variable doesn’t point to any OBJECT. Hence you cannot ACCESS any PROPERTIES on the variable or CALL a method on it.

In TypeScript, the null value is indicated by the ‘null’ keyword. You can check if a value is null as follows:

function greet(name: string | null) {if (name === null) { console.log("Name is not PROVIDED");} else { console.log("Good morning, " + name.toUpperCase());}}var foo = null;greet(foo); // "Name is not provided"foo = "Anders";greet(foo); // "Good morning, ANDERS"


Discussion

No Comment Found