-5

Do if/else statements affect performance?

Edit: Okay this is ridiculous

4

1 回答 1

2

What your colleague is likely referring to is that in some cases assigning a variable every time is faster than checking some condition and then assigning it.

var a = 2;

function slower() {
    if (a !== 0)
        a = 0;
}

function faster() {
    a = 0;
}

Really though, it is pretty ridiculous to consider performance impact of a single if statement considering how powerful today's computers are.

于 2013-03-30T08:21:31.530 回答