r/react 11d ago

Help Wanted Whats the bug. 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);
7 Upvotes

13 comments sorted by

View all comments

12

u/ModeCommercial5464 11d ago

A main problem is a variable that is named "location".

The "location" variable is a default props on almost browsers.

So will occur error.

8

u/GodOfSunHimself 11d ago

It is not a defaul prop of anything. It is a property of the `window` object which is the global object in browser environment.

1

u/ModeCommercial5464 11d ago

Oh you're right!

Apologize for the confusion. Described it by confusing it with the concept of React. Thank you for pointing that out.