Why is it possible to quote the key name of a javascript object, and how is it implemented internally?

under normal circumstances, the key name of a javascript object (usually a string whose key name begins with a character) can be in quotation marks. How does javascript handle the key name of an object? Cause us to be so casual, you can add quotation marks or not! I am a javascript beginner, used to use C language development, this is very do not understand, please expert advice, thank you!

Aug.01,2021

used to be developed in C language, so you have a lot of potential. This actually involves naming rules. Generally, attribute names that do not conform to the specification have to be quoted, but those that conform to the specification can not be added. Let me give you a suggestion. Now that I have mentioned this, I would like to remind you that if you want to take the value of the object, it is best to take the form of square brackets, so that you can avoid not getting the value due to the problem of naming rules. Of course, the form of the point is also possible.


in fact, there is nothing to get to the bottom of this, this is the basic grammatical rule. For legitimate attribute names, use'.' Operation to get the corresponding attribute value, this other language has a similar syntax, but for the user-defined attribute name'.' Syntax, illegal definition, js can not recognize, what to do? Because js defines the relationship between the attribute name and the attribute value as an associative array, you can get the attribute value corresponding to the custom attribute name by getting the value of the array. This is the grammatical rules of the language, how exactly, you need to understand how the language is designed and implemented.

Menu