Comparison and String Operators
Comparison operators test ordering or equality. For two strings, relational comparison uses lexicographic UTF-16 code-unit ordering.
Text order and numeric order answer different questions.
See the mechanism
trueFollow one example
The numeric comparison is true. With two strings, comparison starts at the first differing code unit: "1" precedes "3", so "12" > "3" is false. + joins two strings. Neither behavior sorts numeric input correctly unless you first decide whether the data is text or numbers.
Predict, change and check
Predict: Will "9" > "10" use numeric magnitude or the first differing character?
Test your explanation: Run that comparison beside 9 > 10. Write down the types next to the two results so the reason is visible.
The tasks below ask you to explain that result and apply the idea to different inputs.
Apply and distinguish
Comparison and text joining need explicit inputs
Relational comparison can behave lexicographically for two strings and numerically for other primitive combinations. The displayed strings '10' and '2' therefore do not establish numeric order. Normalize inputs when the feature asks for numeric order rather than relying on a changing mixture of representations.
String concatenation builds new text and does not validate the data embedded in it. Template literals improve readability but do not make untrusted text safe as HTML or SQL. Keep plain text in textContent for DOM output and use the appropriate structured API at other boundaries.
Check your understanding: State the input contract, identify the operation that changes the result, and give one boundary input that would distinguish the correct rule from the mistake described above.