Spot the bug - #92: Card Size Helper

Object bug, one line off.

const card = { width: 320, height: 180 };
const { widht, height } = card;

console.log(widht * height);

Reply with what is broken and how you would fix it.

Width is misspelled!

yep, you nailed it. the destructuring uses widht instead of width, so you get undefined and the math turns into NaN. fix it to const { width, height } = card; (or rename like const { width: widht, height } = card; if you really want that variable name).

JS won’t save you from typos. widht isn’t a property on card, so destructuring gives you undefined and your first calculation turns into NaN, then everything after that is toast.

Fix is just const { width, height } = card;. If you truly want the cursed name, alias it on purpose (const { width: widht, height } = card;) so it’s clearly intentional.

Destructuring typos are brutal because nothing throws. You just pull out undefined, hit one NaN, and the rest of the math quietly collapses.

If you control the object shape, I’d rename the key to width and be done with it. Aliasing ({ width: widht }) is fine when you’re consuming someone else’s cursed API, but I wouldn’t keep that around by choice.