Answer the question
In order to leave comments, you need to log in
Why in JS you can't assign a value to a missing property of an object, but you can assign a value to a missing nested property of an object?
Let's say there is a certain object:
Why the code
Will swear that param is not defined, but if you define another property:
Then it will not swear. Indeed, in both cases, there is no nested param property. Explain how it works const someObject = { param: 'value' }
someObject.another.param = 'value'
someObject.another = {}
Answer the question
In order to leave comments, you need to log in
Before assigning, the compiler looks for the place of the assignment.
someObject - know where to look (this), found
.another - know where to look (someObject), not found
.param - don't know where to look, error
someObject - know where to look (this), found
.another - know where to look (someObject) , Have not found
Will swear that param is not definedI suspect that the compiler will swear not that param is not defined, but that another (undefined) is not defined.
in the first option you are trying to find an apartment in a non-existent house, in the second option you are looking for an apartment that does not exist in the house. as if the first option does not make sense, therefore the error
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question