Predict Keyof Output
Predict Output Medium
Question
What does this code print?
Code
type Person = { name: string; age: number; };
const keys: Array<keyof Person> = ["name", "age"];
console.log(keys.join(", "));
Hint
keyof Person gives the union of keys: "name" | "age".
Explanation
keyof Person produces the type "name" | "age". The array keys contains both valid keys. join(", ") produces "name, age". The type constraint ensures only valid keys can be added.
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.