字符串比较如何在JavaScript中运行?

例如,
javascript中的字符串比较背后的算法是什么工作

'bc' > 'ac' = true/false ?
'ac' > 'bc' = true/false ?

最佳答案 这是使用ECMA-5中的
The Abstract Relational Comparison Algorithm计算的.相关部分引用如下.

4. Else, both px and py are Strings
    a) If py is a prefix of px, return false. (A String value p is a prefix 
       of String value q if q can be the result of concatenating p and some
       other String r. Note that any String is a prefix of itself, because 
       r may be the empty String.)
    b) If px is a prefix of py, return true.
    c) Let k be the smallest nonnegative integer such that the character 
       at position k within px is different from the character at position 
       k within py. (There must be such a k, for neither String is a prefix 
       of the other.)
    d) Let m be the integer that is the code unit value for the character 
       at position k within px.
    e) Let n be the integer that is the code unit value for the character 
       at position k within py.
    f) If m < n, return true. Otherwise, return false.
点赞