Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

JavaScript jQuery Basics (2014) Creating a Password Confirmation Form Perform: Part 2

David Service
David Service
12,928 Points

Use the Created Variables on the Statements in our code?

When Andrew creates a pair of variables to contain the elements we keep targeting,

var $password = $(“#password);
var $confirmPassword = $(“#confirm_password);

we can use them in our functions without a problem.

My question is, can't we also use these variables in our statements later on in the code?

For instance, can we change this:

$(“#password).focus(passwordEvent).keyup(passwordEvent);
$(“#confirm_password).focus(confirmPasswordEvent).keyup(confirmPasswordEvent);

Into this?

$password.focus(passwordEvent).keyup(passwordEvent);
$confirmPassword.focus(confirmPasswordEvent).keyup(confirmPasswordEvent);

Not really an life-or-death issue, but just curious.

Many thanks,

David

David Service
David Service
12,928 Points

Just watched a few more minutes into the video, and Andrew went right ahead and did exactly what I was asking about.