What does the following code output? const a = { x: 1 }; const b = Object.create(a); b.y = 2; console.log(Object.keys(b), Object.getOwnPropertyNames(b), ‘x’ in b);

JavaScript Professional Hard

JavaScript Professional — Hard

What does the following code output? const a = { x: 1 }; const b = Object.create(a); b.y = 2; console.log(Object.keys(b), Object.getOwnPropertyNames(b), ‘x’ in b);

Key points

  • Object.create() sets b's prototype to a
  • Object.keys() returns own properties only
  • Object.getOwnPropertyNames() returns all properties
  • 'x' in b checks for property 'x' in b

Ready to go further?

Related questions