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

JavaScript JavaScript Functions Create Reusable Code with Functions Using Multiple return Statements

Why are we are the value property to the field?

I am confused why we are adding the value to field inside the conditional statement. thanks

if (field.value === "") { return true; } else { return false; }

1 Answer

Steven Parker
Steven Parker
231,268 Points

The conditional doesn't change the field value, it only tests it. In this example it is testing to see if the value is empty (same as a string with no contents).

This example is primarily to illustrate the function of a conditional. In actual practice the result of the comparison could be returned directly without using a conditional:

    return field.value === "";