Const Literal Type
Predict Output Easy
Question
What does this code print?
Code
const x = "hello" as const;
console.log(typeof x);
Hint
as const makes the type the literal "hello", but typeof is still string.
Explanation
With as const, the type of x is the literal "hello" (not the general string). However, at runtime, typeof "hello" is still "string". The literal type is a compile-time concept only.
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.