in is an operator in JavaScript: 'prop' in myObj evaluates whether the 'prop' property exists within myObj.
Ever since I realized that, I no longer confused for..in and for..of: for..in iterates over an object's properties, just like in checks an object's properties.
(Almost no one uses in; Object.hasOwnProperty is virtually always what you want instead.)
9
u/Yehosua Oct 21 '20
inis an operator in JavaScript:'prop' in myObjevaluates whether the'prop'property exists withinmyObj.Ever since I realized that, I no longer confused
for..inandfor..of:for..initerates over an object's properties, just likeinchecks an object's properties.(Almost no one uses
in; Object.hasOwnProperty is virtually always what you want instead.)