for..in and hasOwnProperty [duplicate]

Because if you don’t, it will loop through every property on the prototype chain, including ones that you don’t know about (that were possibly added by somebody messing with native object prototypes).

This way you’re guaranteed only the keys that are on that object instance itself.

Leave a Comment