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

I get the following message " '$' was used before it was defined " while developing on brackets

I get a warning on brackets while writing the following piece of code:

$(".main-header").css("background-color", "red");

it says: '$' was used before it was defined.

It runs fine on the browser regardless, but still I'm kind of new and feels like im doing something wrong. What is it?

Are you attempting to use jquery and where do define jquery in relation to using it?

1 Answer

That warning is simply there to indicate that you are using a variable that has not actually been defined in your script yet. When you actually load your page that variable is created by the jQuery script you embed which is why your code works, but JSLint (which Brackets uses for code checking) has no way to know that since it's just looking at the variables defined in your script.

You can safely ignore the warning, but can also make it go away by adding these two comments at the top of your script:

/*jslint browser: true*/
/*global $, jQuery*/

That will tell JSLint that $ and jQuery will exist globally when the script is loaded even though they are not defined within your script.