Skip to main content
InterviewHubPRO
Section Overview
Q8

Question 8 of 50

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

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

What is the difference between Type Assertions (`as`) and Type Casting?

senior LevelTypeScript

In Simple Words:

  • Type Casting in languages like C# or Java converts data representations at runtime (e.g. converting float bytes to integer).
  • Type Assertion (as Type) in TypeScript is purely a compile-time instruction telling the compiler: "Trust me, I know the type better than you do." It does not convert or sanitize any runtime data!
  • Non-null Assertion (obj!.prop): Asserts that obj is neither null nor undefined. If it actually is null at runtime, it triggers a crash!