Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

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.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7646783
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T10:17:46+00:00 2026-05-31T10:17:46+00:00

var test = test123 var test123 ={ key + test: 123 } This code

  • 0
var test = "test123"
var test123 ={
    "key" + test: 123
}

This code doesn’t work. What is wrong with “key” + test ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T10:17:48+00:00Added an answer on May 31, 2026 at 10:17 am

    Because "key" + test is an expression and not an identifier nor a string literal nor a number literal, which are the only things that are allowed as the key in an object literal.

    You have to use the [] notation after creating the object for such a dynamic key:

    var test123 = {};
    test123["key" + test] = 123;
    

    An identifier is basically the same subset of characters that you can call a variable (letters, numbers, _ and $; may not start with a number), and a string literal is any string enclosed with ' or ".

    So, the only types of keys you can use in an object literal are:

    {
      a0:   true, // valid identifier
      $$_:  true, // same
      123:  true, // valid numeric literal
      012:  true, // same (octal)
      0xf:  true, // same (hex)
      "@":  true, // not allowed as an identifier
      '0a': true  // same
    }
    

    Reference: http://es5.github.com/#x11.1.5.

    PropertyName :

    IdentifierName

    StringLiteral

    NumericLiteral

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Why doesn't this work right? function test() { var start = new Date(2012, 3,
i have this code $test = new test(); $test->var_test = array('one','two'); class test{ var
When I run this code: var Test = function() { return this.stuff; }; Test.stuff
This is the working code: var test = function () { console.log(test.data); }; test.data
When writing code like this jsLint complains about implied globals: var Test = (function(){
I'm getting an unterminated string literal Javascript error with this code: var test =
why does this only alert 1 ? function test() { var myobj = {
I using following code: var search = 'test'; if ($('#sku').find(search) ){ //alert(search); $(document).find(search).css('color','red'); <TABLE>
var Test = (function() { return { useSub: function () { this.Sub.sayHi(); }, init:
Here is my full code import fl.controls.*; var test:MovieClip = new MovieClip(); var btn:Button;

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.