I'm currently reading "Datastructures and Algorithm with JavaScript" by Michael McMillan. On page 39 he implements a clear function for a list, i.e. the function clears out the element of a list.
function clear() {
delete this.dataStore;
this.dataStore = [];
this.listSize = this.pos = 0;
}
Wouldn't assign this.dataStore with undefined or null achieve the same result? Or why not immediately assign an empty array to this.dataStore?
I've read that delete removes a property from an object and if no more references to the same property are held, it is eventually automatically released.
As you can see above, he deletes it and then re-creates it. So, does the delete operator make sense if he doesn't want to release the property anyway? Wouldn't simply re-assigning this.dataStore with an empty array [] be more efficient and equally effective?