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 trialColin Sandlin
4,512 PointsUnderstanding the "checked" value
I'm having a bit of trouble wrapping my mind around this line, at about 5:50 of the video -
const checked = checkbox.checked;
// how does checkbox.checked work?
//I understand it's a true or false value, but why doesn't it have to have an 'if true' statement?
3 Answers
Steven Parker
231,261 PointsYou're right, it will require an "if" statement to test the value. By itself, the assignment doesn't cause any decision to be made by the code. Continue on in the video until about 6:50 and you will see this statement written:
if (checked) {
Isn't that exactly what you were expecting?
Colin Sandlin
4,512 PointsSteven, thanks for your reply. That is what I was expecting, however I still can't seem to understand what the checkbox.checked is doing or how that line operates prior to the 'if' statement?
I'm not sure if my question is making sense, sorry!
Colin Sandlin
4,512 PointsAh, yes it does. I think the syntax of the variable being named 'checked' and having that same terminology later in that line was messing with me. I appreciate your patience.
Steven Parker
231,261 PointsSteven Parker
231,261 PointsThe assignment line just puts a "true" or "false" value into the constant named "checked". This value represents the condition of the box at the moment the assignment runs. The value will be "true" if the box is checked, and "false" if it is not. But on this line, the value is only stored. Is isn't tested until later by the "if".
Does that answer your question?