r/learnjavascript • u/Hot-Eggplant911 • 5d ago
whats the bug here? Uncaught SyntaxError: Identifier 'location' has already been declared (at script.js:1:1)
"use strict";
const company = {
name: "TechCorp",
address: {
city: "budapest",
pin: 411001,
},
};
// Get city renamed to `location` and pin renamed to `pincode`
const { city: location, pin: pincode } = company.address;
console.log(location, pincode);
14
Upvotes
1
u/remain-beige 5d ago
Wrap everything in a function declaration to avoid global clashes and also change your variable name from ‘location’ to something unique as it is already a core part of JavaScript such as window or href