mardi 12 mai 2020

What is quicker in nodeJs to process, else if statements or avoiding them with return?

What is quicker to process in javascript or NodeJS, else if statements or avoiding them with returns?

Case A

function (x) {
  if (x === 12142) {
    return true
  } else if (x === 798789) {
    return false
  } else {
    return true
  }
}

Case B

function (x) {
  if (x === 12142) {
    return true
  } 
  if (x === 798789) {
    return false
  } 
  return true
}

I have a gut feeling that case B is quicker with better performance, but just want to confirm with your feedback.

Aucun commentaire:

Enregistrer un commentaire