DEV Community

Discussion on: Improve your JS skills with those tips #2

lukaszahradnik profile image
Lukáš Zahradník

Can you provide some benchmarks for you approach of property deletion vs. delete? I tried some and ended up with delete being faster. Also, what exactly are "a lot of side projects" which delete causes?

What is exactly your argument (other than "not being a very good code anyway") against the code:

if (condition) { = 
Enter fullscreen mode Exit fullscreen mode

It's more readable than the other ("better") version and does not abuse and operator. It's literally one if statement versus some esoteric-like code golf javascript.

That being said, short circuit "improvements" (abusing && and ||) are also less readable.

codeoz profile image
CodeOz Author

Hey I miss I mean "side effects " 😅! I think benchmark is not the good approach about this, the focus is on "side effect" that can be leads by delete operator. In general in programming we don't encourage people to remove property from a current object since some "logic" can be linked to this property and lead to bug.

For the example you highlight, I mean that the if condition can be avoid, so we should avoid it when we can. In this case we have only one condition and only one property. Imagine that we need to add 10 properties with 10 conditions differents, you will use 10 if?

I'm agree that short circuit don't need to be abusing but it can lead to less DRY (don't repeat yourself).