Are ternary statements faster than if/then/else statements in javascript?
问题 I see a lot of: var something = (is_something_true()) ? 3 : 4; in javascript. Is this faster than var something; if (is_something_true()) { something = 3; } else { something = 4; } Or is it written concisely for convenience? 回答1: Please enjoy this -- if difference is statistically valid then the result (true or false) also matters -- clearly this is just other stuff on the machine having an impact on browser performance: Here is the link There is a fundamental difference between the two, the