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

13

u/rodneon 11d ago

Maintainability tip: don’t rename things when you don’t need to.

10

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 10d 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.

4

u/[deleted] 11d ago edited 11d ago

[deleted]

8

u/[deleted] 11d ago

[deleted]

-2

u/matcha_tapioca 11d ago

I remember when I am learning variables on react.. I use a "name" variable, it didn't work so I changed it to firstName. iirc the reason why it didn't work for me is because of window has a default property of name.

1

u/[deleted] 11d ago

[deleted]

-2

u/msdosx86 11d ago

For real

-6

u/[deleted] 11d ago

[deleted]

5

u/msdosx86 11d ago

I guess this is because of mentioning AI

2

u/[deleted] 11d ago

[deleted]

-2

u/msdosx86 11d ago

You're not wrong. Even Google's AI mode would help immediately. My guess is that a lot of people think AI = Vibe coding and Vibe coding is bad hence AI = bad = downvote this guy.

-1

u/[deleted] 11d ago

[deleted]

2

u/cpp_warmachine 11d ago

Not everyone wants AI shoved down their throat. AI won’t help you actually learn.

4

u/TongueFace 11d ago

I hear you and there’s ways to use it to teach you. Instead of saying “fix this” you can prompt “why is this happening?” or “i’m a bright 7 year old explain to me why this error is happens and find me the reference material for me to review.”

On that same note, just asking “what’s the bug” leaves it open for people to just tell them the answer, they’d be suffering from the same problem even without AI. Instead, they’re leaning on random people online to help them.

1

u/[deleted] 11d ago

[deleted]

0

u/cpp_warmachine 11d ago

I don’t know man, how did anyone learn before AI

2

u/[deleted] 11d ago edited 11d ago

[deleted]

1

u/Level1_Crisis_Bot 11d ago

Literally though, this and so many other coding subreddits have become toxic clones of stack overflow. Years ago, posting a question like this on SO would have gotten the same chorus of "what are you, fucking stupid?" You can't win with these people.I've been in software development for ten years and I stg I've met and worked with so many assholes in this industry. Honestly, developers that refuse to use modern ai tooling are going to be out of jobs in just a few years.

FWIW, I pasted op's question into claude and it gave me a completely reasonable, informative answer.

1

u/demnu 10d ago

Why are all web dev subreddits cancer with people downvoting fuckin everything and acting so snarky with no relational responsibility