What is the hasOwnProperty method?
Here, the object is the name of the object you want to check. Its property is the name of the property you want to check if it is its own property or inherited. The method returns a boolean value, true if the object has its own property, otherwise false.
hasOwnProperty() Return Value
The output contains four lines. ‘coding_ninjas’ object has ‘name’ and ‘vertical’ properties, so the two lines return true as output.
'intern' has only one property, 'name', for which the result is true. ‘role’ is not the property of the ‘intern’ object, so the fourth line of output contains false.
- Chrome (1 and above)
- Edge (12 and above)
- Opera (5 and above)
- Safari (3 and above)
- Firefox (1 and above)
Frequently Asked Questions
Does the hasOwnProperty work on inherited properties or values?
No, the hasOwnProperty does not work on inherited properties or values.
Wanna learn more about web technologies? Why not have a look at web technologies on Coding Ninjas Studio? Don’t stop yourself here. Practice data structures and algorithms, interview questions, DBMS, computer networks, and operating systems to crack the interviews of big tech giants. Explore other fields like machine learning, deep learning, computer vision, and big data. Also, check out Interview Experiences for different companies.