Let's take the ganger in the language specification (the algorithm itself is described here ) (note that it defines < , but the operator > just flips the resulting value).
What the operator does is try to convert both operands to primitive types with preference for numbers:
2. a. Let py be the result of calling ToPrimitive(y, hint Number). 2. b. Let px be the result of calling ToPrimitive(x, hint Number).
In our case, x === stream.getChar() and y === ' ' . Since both operands are already primitive strings, this leads to the original values ββ( px = x, py = y ), and we go to:
4. Else, both px and py are Strings
Now it checks if one of the operands is prefixes of the other, for example:
'abc' > 'abcd' // false 'foo' > 'foobar' // false
What matters if getChar() results in a space, since space is a prefix of itself:
' ' > ' ' // false
We proceed to search for the first character in x and y , which are in the same position in the lines, but have different characters:
Let k be the smallest non-negative integer such that the character at position k inside px differs from the character at position k inside py. (There must be a k, since neither String is a prefix of another.)
(e.g. 'efg' and 'efh' , we want g and h )
The selected characters are then converted to their integer values:
Let m be the integer that is the code unit value for the character at position k within px. Let n be the integer that is the code unit value for the character at position k within py.
And finally, a comparison is made:
If m < n, return true. Otherwise, return false.
And what is it compared to space.
tl; dr It converts both arguments to their integers, and compares them.