1.

What Will Be The Output Of The Code Below? var Employee = { company: 'xyz' } var Emp1 = Object.create(employee); delete Emp1.company Console.log(emp1.company);

Answer»

The output would be XYZ. Here, emp1 OBJECT has company as its prototype PROPERTY. The delete operator doesn't delete prototype property.

emp1 object doesn't have company as its own property. You can test it console.log(emp1.hasOwnProperty('company')); //output : false. However, we can delete the company property directly from theEmployee object USING delete Employee.company. Or, we can also delete the emp1 object using the __proto__ property delete emp1.__proto__.company.

The output would be xyz. Here, emp1 object has company as its prototype property. The delete operator doesn't delete prototype property.

emp1 object doesn't have company as its own property. You can test it console.log(emp1.hasOwnProperty('company')); //output : false. However, we can delete the company property directly from theEmployee object using delete Employee.company. Or, we can also delete the emp1 object using the __proto__ property delete emp1.__proto__.company.



Discussion

No Comment Found