title: Function call to declare object property in JavaScript
body: <p>Is it possible to use function call to set an object property in js? I tried but it didn't work.</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>var name = "Richard";
  
  function showName() {
    var name = "Jack"; // local variable; only accessible in this showName function​
    console.log(name); // Jack​
  }
  console.log(name); // Richard: the global variable
  
  var myObj = {
    name: showName();
  };
  
  console.log(myObj.name);</code></pre>
  </div>
  </div>
  </p>