title: Regarding copying key value pairs of javascript objects
body: <p>**I was trying to create a copy of error object sent by mongoose by doing let error = {...err}.
  err was the original error object. Now when I logged to console(err.name) it shows &quot;CastError&quot; which is expected but (error.name) was giving &quot;undefined&quot; , but when I used error = JSON.parse(JSON.stringify(err)) and then logged both err.name and error.name both are showing expected &quot;CastError&quot; output, my doubt is why {...err} didn't worked
  [When using {...err}<a href="https://i.stack.imgur.com/fKoyr.png" rel="nofollow noreferrer">1</a>
  **</p>
  <p><a href="https://i.stack.imgur.com/ihasO.png" rel="nofollow noreferrer">When using JSON.parse()</a></p>