-5

Do if/else statements affect performance?

Edit: Okay this is ridiculous

2
  • Your fella doesn't know JavaScript? There's no such this as if-then statements. if-else maybe.
    – elclanrs
    Mar 30, 2013 at 8:15
  • Why not write code in your hand? And that give a shoot
    – user2193789
    Mar 30, 2013 at 8:16

1 Answer 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.

Not the answer you're looking for? Browse other questions tagged or ask your own question.