0

What is the difference between Object.id and Object["id"] in JavaScript?

For example

var variable = {
    id: 1,
    other: "other"
}

What is the difference between variable.id and variable["id"] ?

Nikita
  • 1,693
  • 1
  • 6
  • 18
  • 2
    Nothing, except for the fact that you can put any expression between the `[]`. e.g. `const key = "id"; console.log(variable[key])`, or use keys that can't be normal identifiers (e.g. they have a space), like this `variable['my id']` – Scotty Jamison Jun 18 '21 at 22:30

0 Answers0