Solution: Interfaces, Classes, Inheritance, and Modules

Solution: Using an interface

The hasProperty function takes two arguments:

  1. obj, which represents the object of type User.
  2. 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 1200+ tech skills courses.