mercredi 28 octobre 2020

Javascript: Is there a difference in performances when using literals in conditional statements?

this is a very peculiar curiosity that I'm not apparently able to benchmark with significant results.

The following code blocks perform the same simple comparison, they differ only in the order that I use inside the condition:

Code1:

const val = true;
if (val === true) {
  console.log('this is a truism');
}

Code2:

const val = true;
if (true === val) {
  console.log('this is a truism');
}
  • Is there any performance difference?
  • Is one implementation better than the other for any reason?

Thank you guys! 🙏

Aucun commentaire:

Enregistrer un commentaire