What will be the output of the following code?

Technology CommunityCategory: JavaScriptWhat will be the output of the following code?
VietMX Staff asked 3 years ago
Problem
var x = { foo : 1};
var output = (function() {
  delete x.foo;
  return x.foo;
})();

console.log(output);

Above code will output undefined as output. delete operator is used to delete a property from an object. Here x is an object which has foo as a property and from self-invoking function we are deleting foo property of object x and after deletion we are trying to reference deleted property foo which result undefined.