Type Inference Number
Predict Output Beginner
Question
What does this code print?
Code
const x = 42;
console.log(typeof x);
Hint
const x = 42 infers x as number.
Explanation
TypeScript infers x as number from the literal 42. At runtime, typeof 42 is "number". The inferred type is number (not the literal 42) because let/const without as const widens to the general type.
Related Resources
Related Lessons
- Type Inference
Learn inference.
Look up unfamiliar terms
A beginner-friendly glossary explains jargon in plain English — variables, functions, DOM, Promise, and more.
Decode error messages
Plain-English explanations of common errors — what they mean, why they happen, and how to fix them.
Build real projects
Apply what you learned by building guided projects with starter code and solutions.