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 trialCasey Ledbetter
8,731 Points[Error] SyntaxError: Can't create duplicate variable that shadows a global property: 'myHeading' is this video outdate
[Error] SyntaxError: Can't create duplicate variable that shadows a global property: 'myHeading' (anonymous function)
Is the full error code I get when I open up my console. I am using Safari and my code is exactly like the video.
I did changed the constants so they weren't the same as the IDs and it worked. Does this video need to be updated to reflect that or is this unique to safari?
app file /*const myHeading = document.getElementById('myHeading'); const mybutton = document.getElementById('myButton'); const myTextInput = document.getElementById('myTextInput');
myButton.addEventListener('click', () => { myHeading.style.color = myTextInput.value; });*/
index /*<!DOCTYPE html> <html> <head> <title>JavaScript and the DOM</title> <link rel="stylesheet" href="css/style.css"> </head> <body> <h1 id="myHeading">JavaScript and the DOM</h1> <p>Making a web page interactive</p> <input type="text" id="myTextInput"> <button id="myButton">Change headline color</button> <script src="app.js"></script> </body> </html> */
1 Answer
Steven Parker
231,248 PointsThat might be unique to Safari.
I just tried it in Chrome and got no error, even when using "strict" mode.
The program functionality is exactly the same with the const lines removed, which proves that the implicit globals do exist. In fact, the program only works because they exist to begin with, because there's a typo where "mybutton" is created using a lower-case name but the event handler is attached to "myButton" (with capital "B").
But there is apparently no restriction in re-using the names in Chrome.