0

I'm learning JavaScript and just came across something I'm not understanding.

let x = 3;
const y = x++;

console.log(x);

The console logs 4. Why is x logged as 4, when y is a separate variable and seemingly not affecting x? Is x++ not simply being assigned to y? And in that case, why would the value of x be changed?

j08691
  • 197,815
  • 30
  • 248
  • 265
Espskully
  • 97
  • 1
  • 8

0 Answers0