TypeScript Output Prediction Easy +10 XP
Type Assertion
What does this output?
TypeScriptRead-only
const value: any = "hello"; const len = (value as string).length; console.log(len);
What is the output?
Show answer and explanation
Answer: 5
'hello' has 5 characters. The 'as string' assertion tells TypeScript to treat value as a string.
Hint: Count the letters.
What this challenge tests
Output Prediction in TypeScript: type-assertion, basics.