Check if property exists in object

// Write a function that takes an object (a) and a string (b) as argument
// Return true if the object has a property with key 'b'
// Return false otherwise
// Tipp: test case 3 is a bit tricky because the value of property 'z' is undefined
// But the property itself exists
function
myFunction
(
a, b
)
{

return
}
Test Cases:
myFunction({a:1,b:2,c:3},'b')
Expected
true
myFunction({x:'a',y:'b',z:'c'},'a')
Expected
false
myFunction({x:'a',y:'b',z:undefined},'z')
Expected
true

How to solve it

A very simple solution to solve this exercise is to use thein operator. The in operator can be applied to any object. It checks if a property with a certain key exists in the object: const obj = { x: 1 };
console.log('x' in obj);
// output: true
console.log('a' in obj);
// output: false
The value of the property does not matter in this case, even if it is undefined. As long the property itself exists in the object, the in operator return true: const obj = { x: undefined };
console.log('x' in obj);
// output: true