javascript - Choosing right condition in if statement -


lets assume have code:

if (a == 'something') {   doa(); } else {   dob(); } 

my main concern related performance. if in (almost 99%) cases a not equal 'something' need invert conditions , blocks?

if (a != 'something') {   dob(); } else {   doa(); } 

you have condition decide 2 possible outcomes true or false. can't scenario.

if have following scenario:

if (a == 'something') {   doa(); } else if (a == 'something else') {   dob(); } else if (a == 'something else else') {   doc(); } else {   dod(); } 

and condition a == 'something else else' gets true of times, should move top , micro optimization makes sense.

but in existing example you have minimal required code executed.


Comments

Popular posts from this blog

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -