← JavaScript tutorial

JavaScript

Objects

An object groups related values under named keys: const user = { name: "Ada", age: 21 }.

Example: dot notation vs. bracket notation

const student = {
  name: "Ada",
  track: "Frontend",
  isEnrolled: true,
};

document.getElementById("output").textContent =
  student.name + " is studying " + student["track"];

student.name (dot notation) and student["track"] (bracket notation) both read the same kind of value, the difference is that bracket notation lets the key itself be a variable, computed at runtime: const key = "track"; student[key] works, while student.key would look for a literal property named "key", which doesn't exist. Use dot notation by default; switch to bracket notation only when the property name needs to be dynamic.

Try it yourself
Ready to go further?

These free tutorials are a preview, our Frontend Development cohort covers it in depth, with a real project and a cohort alongside you. Closes Nov 30

Enroll in Frontend Development

Cookie preferences

Choose what you're comfortable with. You can change this any time from the footer.

Don't miss out

Ready to build something real?

Create a free account to enroll in a track, and get notified the moment a cohort opens.

Create free account