+ 1
Thruthy IF ELSE statement
Let a = 10; Let b = 11; Let c; console.log(a + “” + b); If (!(a++ >= 10 || b++ >= 11)) { c = a + b; console.log(a + “” + c); } else { console.log(a + “” + b); } // 1011 // 1111 Please can someone explain why I’m getting different output
7 Respuestas
+ 3
Reason is because a in incremented inside if statement with a++, this means a = a +1 after this code but not inside this line.
So if(!(a++>=10 || not important because first is true)) - here a is 10
After this a is 11
Thats why only a is changed not b, and you got 1111 as output
a=11,b=11
+ 2
a++ increment value of variable after this line of code.
Or (||)will return true or false, but if first is true it wont even check second part, because value will be true.
+ 2
Thanks Sanja Panic. That was really helpful
+ 1
Ipang thank you.
0
No problem bro 👌
0
let a=10;
let b=11;
let c;
if(!(a++>=10) || (b++>=11)){
c=a+b;
console.log(`${a}${c}`);
}
else{
console.log(`${a}${b}`)
}