6 ms·
Certainly delete can be useful, but nulling a property has almost the same effect (apart from hasOwnProperty still returning true) - if you're looking at optimi
by gb 14y ago
Certainly delete can be useful, but nulling a property has almost the same effect (apart from hasOwnProperty still returning true) - if you're looking at optimising at the level this article is talking about avoiding delete might well be sensible.
- btipling 14y agoThis could also be horrible advice, because now you're mixing types which will make your code a little bit more complex, and you'll iterate over this null and have to deal with it. If you have an object property set to null you'll iterate over it, if you delete it you wont. As for the performance improvements, let's see the jsperf. https://gist.github.com/4018282 https://gist.github.com/4018282 Edit: I found a jsperf: http://jsperf.com/delete-vs-undefined-vs-null/6 http://jsperf.com/delete-vs-undefined-vs-null/6 Delete is a little slower, but setting null can be too, and setting undefined is the fastest for me in stable chrome.