title: How can I manipulate JSON data without side effects in JavaScript?
body: <p>Consider the following code</p>
  
  <pre><code>var myData = {name: 'John'};
  
  function fixName(data) {
      var newData = data;
      newData.name = 'Mike';
      return newData;
  }
  
  var myData2 = fixName(myData);
  console.log(myData2.name);
  console.log(myData.name);
  </code></pre>
  
  <p>'Mike' is printed twice because within my function, newData and myData point to the same thing.  How can I alter my function so that it has no side effects upon myData?  This means the program should print 'Mike' then 'John'.</p>