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 jQuery Basics (2014) Creating a Mobile Drop Down Menu Using parent(), hasClass() and prop()

Javascript: confused about quotes

I am totally confused about quotes. Why do you use quotes or no quotes. It seems totally random. For example: $option.prop("selected", true); Why is true w/o quotes while "selected" is with quotes as they are both properties and nothing is being quoted in either case? In javascript, is there a rule?

1 Answer

Javascript has different types of data

  • Data with quotes (either single ' ' or double " ") are called strings.

  • Numbers are another type of data, they don't take quotes

  • Booleans (true or false) are another type of value which don't take quotes.

Using your example:

$option.prop("selected", true) 
// "selected" is a string and true is a Boolean

But if true had quotes around it, that would make it a string

Strings can have any value inside of the quotes, including numbers

var example = "73"
// This is a string

I hope this helped