These if checks are unnecessary. Deleting a non-existent property is effectively a no-op. See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/delete