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
Akshaan Mazumdar3,787 Points
Why 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
Hey, 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.
You 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