+ 2
Pls anyone explain this code
3 Answers
+ 11
var a = 3;
var b = 7;
if((a++ > 5) && (b > 4)){ // current value of a=3 is 3>7 no so condition is false
document.write(b);
}else{
document.write(a); //it goes to else outputs 4 (because a is post incremented after previous condition)
}
+ 7
As a=3 and a++ is not greater than 5, so if condition becomes false..
So, the else condition will be executed
in else we have to print a
Initially a=3
after incrementation a++=>a=a+1=> 4
Now, a becomes 4 i.e a=4
Hence, you'll get 4 as output...
+ 4
var a = 3;
var b = 7;
if((a++ > 5) && (b > 4)){
document.write(b);
}else{
document.write(a);
}
Output is 4. That's because a++>5 is false, because a is 3, but after testing it becomes 4.
Since one of the conditions is false in an And statement, the whole is false.
So, a is outputted, which is presently 4.
Hope I helped.