+ 2
Can someone really explain what's going on here?
Why does the first one alert 6 and the next, 5? let a = 3; let b = a++; let c = ++a; alert(++c); // 6 let a = 3; let b = a++; let c = ++b; alert(++c); // 5
2 Réponses
+ 2
You hopefully know the difference between prefix and postfix. Let's run through it:
let a = 3;
let b = a++; //a = 4, b = 3
let c = ++a; //a = 5, c = 5
alert(++c); //c = 6, alerted 6
let a = 4;
let b = a++; //a = 4, b = 3
let c = ++b //b = 4, c = 4
alert(++c); //c = 5, alerted 5
+ 2
Thanks for the clarity. I get it now