14/06/2026
Most developers get this wrong π€―
This JavaScript destructuring example confuses many developers π³
const obj = { x: 1, y: 2 };
const { x: y } = obj;
console.log(y);
π Output: 1
π‘ Why?
In object destructuring:
const { x: y } = obj;
means:
π Take the property "x"
π Store its value in a new variable called "y"
It's equivalent to:
const y = obj.x;
So: obj.x = 1
Therefore: console.log(y);
prints: 1
β οΈ Many developers think it accesses obj.y, but that's incorrect.
π₯ Common JavaScript interview question!
javascript destructuring example
object destructuring javascript
javascript aliasing destructuring
javascript interview question
js tricky questions
destructuring assignment explained
javascript output prediction
frontend interview questions
coding shorts javascript
learn javascript fast