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 trialAkshaan Mazumdar
3,787 PointsWhy are we using - const main = document.queryselector('main'); ? Instead can we write whole statment in the end?
Instead can we write document.queryselector('main').innerHTML(...) i.e the entire statement together in the end.
Don't really understand the importance of const main in here
2 Answers
Wendy Cortes
Full Stack JavaScript Techdegree Graduate 16,375 PointsHey, you are right that you can write it all together. Declaring the variable may just make it easier to understand or provide less errors in the future. If you have to use main in the future, you don't have to continue writing document.querySelector('main') each time.
josephweiss2
7,657 PointsYou CAN do it, Just we are looking to make it the shortest possible so if you make a variable from this main element then when ever you want to select it you just write the variable name and it selects the element