0
answer is 3 but can someone please explain how and why :
let a,b,c; a=1; b=5; c=7; if(++b+a > b++){ console.log(b-4) }
7 Answers
+ 2
in the condition, there are left hand side and right hand
left hand side: ++b+a
right hand side: b++
left hand side is evaluated first
++b+a is (++b) + a
a is 1
b is 5
++b is 6,
so (6) + 1
so left hand side is 7
right hand side is b++
b is 6, so right hand side is 6.
then, b++ so b becomes 6 + 1 becomes 7.
+ 3
in the condition, there is ++b and b++
https://www.sololearn.com/learn/JavaScript/1130/
They both increases b by 1
+ 2
++b is pre-increment, b becomes 6, and left hand side is 6+1=7
b++ is post-increment, right hand side is 6, and then b becomes 7.
Because 7 > 6 is true,
log 7 - 4 which is 3
p. s. this is bad practice. only good for brain teaser. don't write in this way in real projects.
+ 1
But the value of b is 5 ,
How come log 7-4 But not 5-4???
+ 1
So value of b becomes 7..
Thank you đ
0
You need to also know why it is comparing 7 > 6
0
I got that but couldn't understand how b value became 7