title: Should we care about JS non-primitive values mutability?
body: <p>Imagine you have a method, which purpose is to modify an array of objects, <strong>and return</strong> the the new version of it.</p>
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>const likePosts = (posts) =&gt; posts.map((post) =&gt; {
    post.isLiked = true
    return post;
  });
  
  const originalPosts = [{ isLiked: false }, { isLiked: false }];
  
  const newLikedPosts = likePosts(originalPosts);
  
  console.log(newLikedPosts);</code></pre>
  </div>
  </div>
  </p>
  <p>But, as JS non-primitive values are mutable, if after executing the code, we log the originalPosts, we will see how the isLiked field is not false, it has been modified to true too!</p>
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>const likePosts = (posts) =&gt; posts.map((post) =&gt; {
    post.isLiked = true
    return post;
  });
  
  const originalPosts = [{ isLiked: false }, { isLiked: false }];
  
  const newLikedPosts = likePosts(originalPosts);
  
  console.log({ newLikedPosts });
  
  console.log({ originalPosts });</code></pre>
  </div>
  </div>
  </p>
  <p>Should we care about this thing? I mean, for example, in this scenario, it does not matter whether &quot;originalPosts&quot; is updated, since it is useless data for the code after executing &quot;likePosts&quot;.</p>
  <p>If we care about data mutation when it is not necessary, we might be doing extra cloning and, consequently, negatively affecting performance, right?</p>
  <p><strong>In order words, when you code JS, are you constantly cloning data to avoid mutations where is it not really necessary?</strong></p>