Safe property access

Report a typo

Write a TypeScript function called safeAccess that takes an object of type unknown and a property name as a string. The function must safely access the property of the object and return its value if it exists. If the property doesn't exist or the input object is not an object, the function must return undefined.

Sample Input 1:

Sample Output 1:

This is a prop
undefined
Write a program in TypeScript
// write your code here
function safeAccess() {

}

Create a free account to access the full topic