Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialTobias G
2,455 PointsNaming HTML ID the same as const
I get an error in the console when giving my HTML elements the same name as the const in the JavaScript document. When I write:
<button id="myButton"></button>
And then in Javascript:
const myButton = document.getElementById('myButton');
I get this error in the console:
SyntaxError: Can't create duplicate variable that shadows a global property: 'myButton'
Tobias G
2,455 PointsYeah, I figured it must've been a bug or something. Seems strange how this isn't fixed yet. Thanks for the info!
1 Answer
Nathan Gallagher
21,518 PointsThis is apparently a problem Safari has with declaring a let/const variable that shares the same name as a selected id attribute. I had some variables declared with const as you did and got the same error. Changed to let and still got it. Changed to var and it worked.
Gonras Karols
17,357 PointsGonras Karols
17,357 PointsLooks like it's a specific bug happens in safari. That's what i found - https://bugs.webkit.org/show_bug.cgi?id=159270