Per "strict mode" in JavaScript, you should use === when comparing values in an if-statement. However, when dealing with truthy/falsy values, this can lead to very long if-statements:
if (a !== null && a !== undefined && a !== '' && a !== 0) {}
To get around this, I've started using !!
if(!!a === true) {}
to cast the value as a boolean. However, I'm concerned there's a performance impact. According to my JSPerf (http://ift.tt/1Yliw15), This approach is 30% slower than the long form of the if-statement.
Am I way off base here? Has anyone else noticed a performance hit?
Aucun commentaire:
Enregistrer un commentaire