Q:

Is it possible to deep copy using ES5 JavaScript? 

Is it possible to deep copy using ES5 JavaScript? 
The problem I'm currently having is properties nested more than 2 levels deep appear to be copying by reference instead of by value. 
Here's what I've currently implemented to copy ...
// Clone an object and return the clone
function clone (obj) {
    var newObj = (obj instanceof Array) ? [] : {}; 
    for (var prop in obj) {
        if(typeof obj[prop] === 'object') {
            newObj[prop] = clone(obj[prop]);
        }
        newObj[prop] = obj[prop]
    }
    return newObj;
};

And here's the code used to test:
const a = { a: 1, b: { c: 2 }};
const b = clone(a);

a.a = 10;
b.a == a.a; // false

a.b = 10;
b.b == 10; // false

a.b.c = 10;
a.b.c == b.b.c; // true

The last one changed the value of c in both a and b objects.  The c property appears to be a reference type. 
How can I ensure that all values are copied by value and are not references? 

A:

You can always use the poor man's deep clone by stringifying and then parsing:

function clone (obj) {
    return JSON.parse(JSON.stringify(obj));
};

const a = { a: 1, b: { c: 2 }};
const b = clone(a);

a.a = 10;
console.log(b.a == a.a); // false

console.log(a.b = 10);
console.log(b.b == 10); // false

console.log(a.b.c = 10);
console.log(a.b.c == b.b.c); // true

Using stringify/parse doesn't copy functions and RegExps, hence the "poor man".  A better option is to use a module, such as clone that can clone everything. 

A:

You are cloning nested objects, but then overwrite them again with the original object:
if(typeof obj[prop] === 'object') {
    newObj[prop] = clone(obj[prop]);
}
newObj[prop] = obj[prop]

Try this instead:
if(typeof obj[prop] === 'object') {
    newObj[prop] = clone(obj[prop]);
} else {
    newObj[prop] = obj[prop]
}

