Solution: Interfaces, Classes, Inheritance, and Modules
Review the solutions to the challenges discussed in the previous lesson.
Solution: Using an interface
The hasProperty
function takes two arguments:
obj
, which represents the object of typeUser
.prop
, which is the string representing the property to check for.
Inside the hasProperty
function, we use the in
operator to check if the given prop
exists in the provided obj
. If the property is found, it returns true
; otherwise, it returns false
.
Get hands-on with 1400+ tech skills courses.