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

This is a question based on the teacher's notes.

The script shows - Example: loop that runs 10 times

var counter = 1;
while (counter <= 10) {
    console.log(counter);
    counter += 1;
}

Now, when running this in the console, I get the number 1 - 11. With the 11th number not showing a debugger link next to it. Can someone explain why I'm seeing this?

VM96:3 1 VM96:3 2 VM96:3 3 VM96:3 4 VM96:3 5 VM96:3 6 VM96:3 7 VM96:3 8 VM96:3 9 VM96:3 10 11

1 Answer

The loop itself only prints out the numbers 1 to 10. But the console is setup to automatically print out the return of the last command performed. Since the last operation performed is counter += 1 which returns 11 that is also printed out.

Since it is technically not something the code itself printed out it does not have any debug info associated with it. You could remove the console.log line from the code entirely and you would still get 11 printed out if you ran the code.