As I've been reading tutorials on the native drag and drop events, I've come across a conditional that checks for e.preventDefault
before calling e.preventDefault()
. This conditional is written either as:
e.preventDefault && e.preventDefault();
or
if (e.preventDefault) {
e.preventDefault();
}
The tutorials are Native Drag and Drop by Remy Sharp, Drag and Drop and Automatically Send to the Server by Remy Sharp, and Implementing Native Drag and Drop by Matt West.
I've never encountered this pattern before. I'm accustomed to seeing e.preventDefault()
called without the conditional. When would e.preventDefault
be falsy and is it best practice to use this phrasing in every instance where e.preventDefault
is being called?