ganqqwerty / 123-Essential-JavaScript-Interview-Questions

JavaScript interview Questions
BSD 3-Clause "New" or "Revised" License
5.01k stars 1.18k forks source link

Question 29: check for null #59

Closed vibl closed 5 years ago

vibl commented 6 years ago

In "Question 29. Write a function called deepClone which takes an object and creates a object copy of it.", the deepClone function should check for a null value:

if( typeof object[key] === 'object' && object[key] !== null )...

What's more, we usually want to also check for hasOwnProperty().

ganqqwerty commented 5 years ago

fixed check for null. About hasownproperty I'm not that sure...