Thruthy IF ELSE statement | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 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

16th Oct 2021, 9:39 AM
Ibrahim Yusuf
Ibrahim Yusuf - avatar
7 Answers
+ 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
16th Oct 2021, 11:37 AM
PanicS
PanicS - avatar
+ 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.
16th Oct 2021, 11:39 AM
PanicS
PanicS - avatar
+ 2
Thanks Sanja Panic. That was really helpful
16th Oct 2021, 11:46 AM
Ibrahim Yusuf
Ibrahim Yusuf - avatar
+ 1
Ipang thank you.
16th Oct 2021, 12:13 PM
Ibrahim Yusuf
Ibrahim Yusuf - avatar
0
No problem bro 👌
16th Oct 2021, 12:18 PM
Ipang
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}`) }
16th Oct 2021, 9:29 PM
Jasy Fabiano
Jasy Fabiano - avatar