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!
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
Farid Lavizadeh12,006 Points
I don't get the expected error when using "let" with the same name twice.
For the following code, I don't get an error on Chrome Console - I just get "15" as value:
let score = 5; score += 10;
let score = 20; console.log(score);
Steven Parker228,026 Points
Odd, when I put those lines into the Chrome console simultaneously I get:
"Uncaught SyntaxError: Identifier 'score' has already been declared at <anonymous>:1:1"
if you put into console together as script you will get an error "Uncaught SyntaxError: Identifier 's' has already been declared" because it works as one script and it is not allowed to declare the same var twice with "let"
let score = 5; let score = 20;
if you enter the same 2 declarations individually into console, one by one, it is like 2 different scripts and you will not get any errors
It will show 15 as a result if you write only: let score = 5; score += 10; Try to copy the code as you wrote it here and paste it in console. You will get the error.
Are you assigning the values directly from chrome dev tools? If so you will not get an error, but if you follow this lesson from your code editor will display the same error message as Guil.
ChienTsun Chan7,042 Points
I put the same code line as u, but I indeed got the error "Identifier has already been declared".