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 trialkaran Badhwar
Web Development Techdegree Graduate 18,135 Pointsempty String
let items = '' V/S let items;
Why the second declaration adds Undefined to the <li> Tags and on the other hand, the first one have an empty space, so same as it should add some empty space, but it doesn't !!
1 Answer
Jason Larson
8,359 PointsThe second declaration adds Undefined because that is the default value whenever you use let
to declare a variable and don't initialize it. The first declaration doesn't add a space at the beginning because it's not a space. It's an empty string, which is a quote followed by a quote. A space would be a quote followed by a space, followed by a quote. There is no space in the declaration, which is why you don't see any space at the beginning of the string.
Note that even if you declare it with a string, and there was a space at the beginning of the string, once it's converted to HTML, the extra space won't matter.
karan Badhwar
Web Development Techdegree Graduate 18,135 Pointskaran Badhwar
Web Development Techdegree Graduate 18,135 PointsHi jason, Thanks for the explanation. I got it