Tuple Access
Predict Output Beginner
Question
What does this code print?
Code
const t: [string, number] = ["hi", 42];
console.log(t[1]);
Hint
Tuple elements have known types at each position.
Explanation
The tuple t is ["hi", 42]. t[0] is string "hi", t[1] is number 42. TypeScript knows t[1] is number from the tuple type definition.
Related Resources
Related Lessons
- Arrays & Tuples
Learn arrays/tuples.
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.