var a="1";
b={a:a},
the b variant isn’t {“1”:1},why will this happened?
also want to know if i want to get the result what i want ,how can i solve this problem
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
JavaScript has a syntax quirk where the bit on the left-hand side of the
:in an object literal isn’t an expression like the bit on the right-hand side.It can be either a quoted string literal, or an identifier token. In the case of an identifier, the token is taken verbatim, as if it were a quoted string. So
{a:"1"}is the same as{"a":"1"}.If you want to use an expression as a property name, you have to do so using the
[]property access operator: