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 trialdamon5
11,405 PointsOnce a const is declared as document.createElement, when we call the variable is it referencing the created element..?
const filterCheckBox = document.createElement('input');
Does this act almost as a function in a sense for creating an input element or is it creating the element when first used and then the const refers to that created input element thereafter?
2 Answers
Jamie Reardon
Treehouse Project ReviewerConst is a constant variable that's value can never be changed once a value has been assigned/referenced to it. Since the teacher knows that he will need to use the create element method, it is being assigned to a variable to add logic and clean code to the script's functionality. You can use a const just like var and let variables except for reassignment. It is not a function, it is a variable and acts the same just as any other variable.
It doesn't actually create the element, as you need to use the likes of the appendChild method to insert the new element into the DOM. It holds the information ready for when needed to use.
damon5
11,405 PointsOh I understand now, thank you.