Computed Property Fill
Fill in the Blank Medium
Question
Fill in the blank to use the variable `key` as a dynamic property name.
Code
const key = "dynamic";
const obj = { [___]: "value" };
console.log(obj.dynamic);
Hint
Use square brackets with the variable name for computed properties.
Explanation
Computed property names use square brackets [key] to evaluate an expression as the property name. { [key]: "value" } creates an object with the property name equal to the value of key (which is "dynamic"). So obj.dynamic is "value".
Related Resources
Related Lessons
- JavaScript Objects
Learn about computed properties.
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.