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 Basics (Retired) Making Decisions with Conditional Statements Review Conditional Statements and Comparison Operators

Andy tran
Andy tran
7,112 Points

Comparison of two strings

( 'lion' > 'zebra' ). Why is this condition false? I thought the first letter 'l' came before letter 'z' should be greater, so the string 'lion' should be greater than string 'zebra'.

1 Answer

Steven Parker
Steven Parker
231,007 Points

Since "l" comes before "z" in the alphabet, "l" has a lower value than "z". So a word starting with "l" has a lower value than a word starting with "z".

So "lion" < "zebra" (and 'lion' > 'zebra' is false).

Andy tran
Andy tran
7,112 Points

So the first word with the first letter that comes before the first letter of the second word has lower value than the second word right. So, ''apple'' has a smaller value than '' bear' right cause letter 'a' in string 'apple' comes before letter 'b' in string 'bear'.

Steven Parker
Steven Parker
231,007 Points

Yes, just like in numbers 1 comes before 3 so 1 is less than 3.