6
fyroc
8y

Do you prefer?

var foo = true;
if (some condition){
var foo = false;
}

Or

if (some condition){
var foo = false;
}
else{
var foo = true;
}

Comments
  • 4
    first is way more intuitive.. "have this, but update it if condition matches" readability wins
  • 2
    First every time, the else block is just useless confusion
  • 3
    Second one doesn't work in languages like Java, because of scope reasons.
  • 0
    The former
  • 11
    I prefer -

    var foo = some_condition;

    Keep it simple. :-)
  • 4
    var foo = (some condition) ? 'bar' : 'blah';
  • 2
    The first. Why are you redeclaring foo though? You already said "var foo" but then you do it again in the conditional block. Wouldn't it just be "foo" in there?
  • 3
    foo = condition
    ;)
  • 0
    Is this a trick question. Obviously, make sure it exists first, and assume the worst.
Add Comment