which would be better if i do this:
if(message == \'redirect\')
{
is_valid.accepted = true;
}
else if(message == \'invalid id\')
{
is_valid.accepted
It depends on your definition of better. Do you want it to be a better reading experience or better performance?
I always jsPerf things. I don't really care much about readability if it makes my code faster/proper.
Here is a jsPerf of a bunch of different switch vs. if/else if/if ==/if === statements.
http://jsperf.com/switch-if-else/16
This is revision 16 of the test. So if you are looking at this 10 weeks from now make sure you scroll to the bottom and grab the most recent test.