main.js
1
2
3
4
5
6
7
8
9
function clone(obj) {
  if (typeof obj === 'object' && obj !== null) {
    return Object.assign({}, obj);
  }
  return null;
}
console.log(clone({name: 'John'})); // => {name: 'John'}
console.log(clone(15));             // => null
console.log(clone(null));           // => null
Native Browser JavaScript