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 Comparison Operators

Because the first letter of the string on the left, the A in apple,
comes before the first letter of the second string

Because the first letter of the string on the left, the A in apple,
comes before the first letter of the second string, the B in bear.
That is A comes before B in the alphabet.

1- I don’t understand how A<B is ‘true’. A is before B.. isn’t it A>B? 2- “That is if you compared a number and a letter, a number is less than a letter.” Meaning, 1 < A?

3 Answers

Dan Weru
Dan Weru
47,649 Points

Jasmin chang , Good question. Think of it this way, if you were to arrange A-Z sequentially, you would have:

1. A
2. B
3. C
...
26. Z

This way, A = 1 and B = 2 hence,

A < B // 1 is less than 2 :)
Cheo R
Cheo R
37,150 Points

I believe it's because of the charcodes:

console.log(String.fromCharCode(65));   // A
console.log(String.fromCharCode(66));   // B
console.log(String.fromCharCode(97));   // a
console.log(String.fromCharCode(98));   // b

console.log(String.fromCharCode(49));   // 1
console.log(String.fromCharCode(57));   // 9

thanks, guys, so 'before' means.. smaller? I guess 'before' meaning is what's tricking me here.