JavaScript JavaScript and the DOM Making Changes to the DOM Getting and Setting Text with textContent and innerHTML

Rod R
Rod R
3,049 Points

step 1 in demo causes error- Uncaught SyntaxError: Identifier 'myHeading' has already been declared at <anonymous>1:1

I launched the workspace for this video and the first step is causing a console error. Guil is entering > let myHeading = document.querySelector('h1'); But when I do the same I get a console error: Uncaught Syntax: Identifier 'myHeading' has already been declared at <anonymous>:1:1 Can I clear it somehow? Here is the default HTML in the workspace:

<!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>
<p>Things that are purple:</p>

<script src="app.js"></script>

</body> </html>

I launched the webpage, opened the console, and typed:

let myHeading = document.querySelector('h1');

How can I get past this error to code along with Guil?

Steven Parker
Steven Parker
200,540 Points

This is a JavaScript issue, yet it looks like you've only shared the HTML file. But you can share the entire workspace easily by using the "snapshot" function (the camera icon) and then posting the link it gives you.

1 Answer

Steven Parker
Steven Parker
200,540 Points

The app.js file that your HTML loads currently contains just one line: "var myHeading;" So it is indeed already declared.

You could either remove that line from the file, or when you enter your console code, just omit the keyword "let".