9. What would happen, if you tried to assign result of void function to a variable?

Type void despite it's unique appliance is in TypeScript same type as any other - that's why there's no problem with assigning it to any variable, as long as it's type is not defined yet or it's void as well.

const voidFunc = (): void => { return; } const val = voidFunc(); const x: string = val; // Type 'void' is not assignable to type 'string'
devFlipCards 2024

Do you accept cookies?

Cookies are small amounts of data saved locally on you device, which helps our website - it saves your settings like theme or language. It helps in adjusting ads and in traffic analysis. By using this site, you consent cookies usage.