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 trialPeter Vanderlind de Oliveira
7,376 PointsCan I have variables inside of a variable in JavaScript?
I'm trying to understand the following:
const input = document.querySelector("form input"), counter = document.querySelector("form .counter"), maxLength = input.getAttribute("maxlength");
I don't understand what the commas are for and I would like to know if counter and maxLength are variables inside input.
1 Answer
Steven Parker
231,236 PointsThose are separate assignments of variables, and none are "inside" any other. The commas just allow the declarations to share the same "const" keyword, but for clarity each assignment could be on a separate line (perhaps that's what you intended but forgot to use formatting.
For future postings, use Markdown formatting to preserve the code's appearance and retain special symbols.