Set object key to value of variable - why have two different ways?
<p>In JavaScript, if you have the following code: </p>

<pre><code>  var map_id = 100;
  var myobj = {};
  myobj[map_id] = 6;
  var myobj2 = { map_id : 6 };
  console.log(myobj, myobj2);
</code></pre>

<p>The console output is as follows: </p>

<pre><code>{ '100': 6 } { map_id: 6 }
</code></pre>

<p>Questions: </p>

<ol>
<li>Why does JavaScript syntax work differently in these two different cases - why is they key in <code>myobj2</code> set to the literal <code>map_id</code> rather than <code>100</code>? What is the reasoning behind having this difference?</li>
<li>Is there any way to set the key to the value of the <code>map_id</code> variable <em>in a compact, one-line way</em>, rather than having to define the object separately first?</li>
</ol>

<p>Thanks. </p>
