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 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
217,443 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
217,443 Points

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