Recently, a friend was asked this question in an interview:

How would you clone an object in pure JavaScript?

Most people’s knee-jerk┬áreply to this would be something along the lines of using jQuery.__extend(), but since this question asks specifically to use pure JavaScript, we’re going to have to get creative.

Let’s start by looking at some solutions that seem correct, but aren’t. For the purpose of this post, we’ll use the following example: Continue reading “How to clone an object in JavaScript?”