Skip to content

Instantly share code, notes, and snippets.

@nola
Last active December 29, 2015 20:19
Show Gist options
  • Select an option

  • Save nola/7722909 to your computer and use it in GitHub Desktop.

Select an option

Save nola/7722909 to your computer and use it in GitHub Desktop.
//The delete operator deletes an object, an object's property, or an element at a specified index in an array. Syntax:
delete objectName;
delete objectName.property;
delete objectName[index];
delete property; // legal only within a with statement
//If the delete operator succeeds, it sets the property or element to undefined.
//The delete operator returns true if the operation is possible; it returns false if the operation is not possible.
x = 42;
var y = 43;
myobj = new Number();
myobj.h = 4; // create property h
delete x; // returns true (can delete if declared implicitly)
delete y; // returns false (cannot delete if declared with var)
delete Math.PI; // returns false (cannot delete predefined properties)
delete myobj.h; // returns true (can delete user-defined properties)
delete myobj; // returns true (can delete if declared implicitly)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment