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 trial

JavaScript JavaScript and the DOM (Retiring) Traversing the DOM Using previousElementSibling and insertBefore

Declaring variable in the console is throwing an error

I'm trying to follow along by typing in the console, and I'm getting an error: VM91:1 Uncaught SyntaxError: Identifier 'li' has already been declared at <anonymous>:1:1

Steps to recreate:

  1. Launch workspace
  2. Click the eyeball to view in browser
  3. Open dev tools in browser > click Console
  4. Type let li = listUl.querySelectorAll('li')[3] and hit enter
  5. I get this error: VM91:1 Uncaught SyntaxError: Identifier 'li' has already been declared at <anonymous>:1:1
  6. if I just type li and hit enter, I get VM98:1 Uncaught ReferenceError: li is not defined at <anonymous>:1:1

Any idea what's causing this?

Steven Parker
Steven Parker
231,271 Points

To facilitate recreation of the issue, make a snapshot of your workspace and post the link to it here.

1 Answer

Steven Parker
Steven Parker
231,271 Points

I tried to replicate this issue using Chrome, but I didn't get the "already defined" error. I did, however, get the "li is not defined" error.

I'd guess this is because the console commands are executed in a temporary context, so anything created with "let" is immediately disposed. I didn't have the same issue using "var". But normally I would take advantage of implicit global declarations and not use either when establishing variables in the console.