Javascript Style Tip: Use "in" and "delete"

1 · isaacs · June 18, 2007, 5 p.m.
Javascript provides two very handy operators, in and delete. Consider this code fragment: var obj = {  foo : 'quux',  bar : 'baz',  doSomething : function () {   // do something...  } }; So, we’ve created an object, and then some other things happen. Later in the code, we want to remove the “foo” property, so we do this: obj.foo = undefined; Still later, we only want to do something if the foo property has not been unset, so we check it: if ( obj.foo !== undefined ) {  // do something } That wo...