Stephanie Franco9,026 Points
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:
- Launch workspace
- Click the eyeball to view in browser
- Open dev tools in browser > click Console
- Type let li = listUl.querySelectorAll('li') and hit enter
- I get this error: VM91:1 Uncaught SyntaxError: Identifier 'li' has already been declared at <anonymous>:1:1
- 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 Parker177,725 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.