Linked Questions
41 questions linked to/from Why is one string greater than the other when comparing strings in JavaScript?
29
votes
6
answers
32k
views
Why is string "11" less than string "3"? [duplicate]
if ('11' < '3') alert('true');
It's obvious that it's not comparing them by length but by encoding instead. However, I don't understand how it works. I need some explanation :-)
8
votes
4
answers
3k
views
How does string comparison work in JavaScript? [duplicate]
What the algorithm work behind string comparison in javascript, for example
'bc' > 'ac' = true/false ?
'ac' > 'bc' = true/false ?
1
vote
1
answer
2k
views
Why does "10" > "9" = false? [duplicate]
Is this a failure in JavaScript's attempt to convert them to numbers? If so, what numbers are they being converted to? Or what is the logic behind the string 10 being less than the string 9?
0
votes
1
answer
430
views
Why in javascript "100" < "5" returns true? [duplicate]
I had a bug in my code where I was comparing strings instead of numbers.
I was doing "100" < "5" and it was returning true.
Why does javascript think that "100" is less than "5"?
3
votes
3
answers
203
views
java script string comparison [duplicate]
I took a JS course on a website , and in one of the lessons there was a piece Of code that did not make sense to me :
the code is in the picture , why str1 is less then str2 ?
0
votes
1
answer
236
views
Bug in Javascript type coercion [duplicate]
I'm having this strange bug with Javascript and type coercion (automatic conversion of variables' type made by Javacript).
Here is the code
console.log('23' < '3');
that is inside a file called ...
0
votes
2
answers
77
views
Javascript string and character comparision [duplicate]
Why does 'Mystery!' <= 'Z' equal true but 'the' <= 'Z' equal false but both
'Mystery!' >= 'A' and 'the' >= 'A' equal true. How does such comparision work?
1
vote
4
answers
160
views
What is happening when I set i equal to a string in a for loop? [duplicate]
Say I have a for-loop
for (let i = 6; i <= 10; i++) {
console.log(i);
};
/*
logs the expected...
6
7
8
9
10
returns undefined
*/
But if I cast those numbers as strings...
for (let i = "...
0
votes
1
answer
168
views
Why does it work to compare string values of invalid numbers? [duplicate]
I was playing around with comparing version codes in JS and found that these types of comparisons work consistently and I have no idea why:
"3.4.06" < "3.4.02" (false)
"3.3.01" < "3.4.02" (...
-9
votes
1
answer
212
views
Does the expression "a" < "A" evaluate to true or false? Why? [duplicate]
I believe this is false, because the strings do not have a value to be measured. However, I may be wrong so I'm hoping someone can offer a second opinion.
console.log("a" < "A");
0
votes
1
answer
123
views
Javascript - I have a problem using toFixed() in (if else) [duplicate]
I am new to javascript.
I'm trying to code a simple program which has 2 variables, each one contains an average number of some calculations, and using if else it should print the variable which ...
-1
votes
1
answer
72
views
javascript, problem with printing largest number entered [duplicate]
The program is required to terminate if 0 is entered, otherwise it will keep going. If 0 is entered i need to print to the console the largest value entered.
Need some help fixing this code. it doesn'...
0
votes
1
answer
64
views
Why "Hello" > "World" is returning false [duplicate]
Can anyone explain me why this:
"Hello" > "World"
is returning false?
2
votes
0
answers
52
views
How does JavaScript compare strings which contain digits? [duplicate]
Could someone explain how does JS compare alphanumeric strings? For ex. why the following returns me 'false' when I run it in browser console:
'abc' > 'abc.15' // false
And why this returns 'true':...
-1
votes
2
answers
44
views
when you compare 2 strings what are you comparing exactly [duplicate]
with javascript when you compare 2 strings what are you comparing exactly
return "hello" > "hola"
this will return false, why ?