TypeScript Data Type - Void

Similar to languages like Java, void is used where there is no data. For example, if a function does not return any value then you can specify void as return type.

Example: void
function sayHi(): void { 

let speech: void = sayHi(); 
console.log(speech); //Output: undefined

There is no meaning to assign void to a variable, as only null or undefined is assignable to void.

let nothing: void = undefined;
let num: void = 1; // Error
Want to check how much you know TypeScript?