Should I use one over the other? Is using them all together better? Thanks.
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
prop in objchecks whetherobjhas a property namedpropat all, even if it’s just inherited from a prototype.obj.hasOwnProperty(prop)checks whetherobjitself holds a property namedprop; it ignores properties inherited from prototypes.obj[prop]gets the value of thepropproperty.Use whichever one is appropriate for what you’re trying to accomplish
Note: In all three cases,
propmust be a string.