delete operator in javascript code example

Example 1: javascript delete key from object

let person = {
  firstname: 'John',
  lastname: 'Doe'
}

console.log(person.firstname);
// expected output: "John"

delete person.firstname;

console.log(person.firstname);
// expected output: undefined

Example 2: what is the function of delete operator in javascript

var student= {age:20, batch:"ABC"};
delete student.age;

Example 3: js Property Assignment delete

delete objectName['Property Name'];
delete objectName.propName;