Skip to main content
InterviewHubPRO
Section Overview
Q5

Question 5 of 50

Part 1: Basic & Foundational TypeScript (Junior / Entry-Level)

10%
TypeScript Master (50 Qs)•Part 1: Basic & Foundational TypeScript (Junior / Entry-Level)

How do Function Signatures and Return Types (`void` vs `never`) work?

junior LevelCode ExampleTypeScript

In Simple Words:

  • void: Indicates a function completes execution without returning a value (returns undefined implicitly).
  • never: Indicates a function never finishes successfully—either it throws an uncaught exception or enters an infinite loop (while(true)).
typescript
function logMessage(msg: string): void {
  console.log(msg);
}

function fail(msg: string): never {
  throw new Error(msg);
}