+ 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 Respostas
+ 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}`)
}