L
L
lssssssssssl2021-06-14 11:36:32
JavaScript
lssssssssssl, 2021-06-14 11:36:32

Why are we able to create a variable and an object key with the same name?

After all, an object does not create its own scope. Why then is this possible?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
Klein Maximus, 2021-06-14
@kleinmaximus

let x = 1;

const y = {
  x: 2
}

In this case, the name of the first variable will be x, and to get the field xfrom the object y, you need to refer to y.x, which will, in fact, be the full name of the field, and it is different from x.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question