delete

The delete operator is used to delete a property from an object and an array item from an array. The item within the array is not actually deleted. Instead, its value is overwritten by making the value of the item undefined. JavaScript automatically handles any memory re-allocation. It should benoted that prior to the JavaScript version 1.2, the item within the array was overwritten with a NULL instead of with an undefined value. It should also be noted that those objects created with var statements are not effected by this operator.

syntax:

delete property or array item

EXAMPLE

variableOne = new Date();

document.write("The date is " + variableOne.getDate());

delete variableOne;

document.write("The contents of variableOne are " + variableOne);

The above example creates an instance of the date object. The results of the getDate() method are written to the screen with a document.write.statement. The varibale holding the date (variableOne) is then deleted, which will most likely throw an error such as "variableOne is undefined".