I wanted to see why indicating a value of type string , in this case '10' as a condition within this loop, works correctly.
At a conceptual level, what is happening?
do {
console.log(valorInicializado);
valorInicializado++;
} while(valorInicializado < '10');
Just that, thank you very much.
Among the "curiosities" of Javascript, it stands out that it is not a typed language, that is, you can declare a variable by assigning a numeric value and then change it to a string or another data type.
This is why the operators will try to convert the elements involved so that they all have the same type, except when strict comparison operators are used .
In the case of greater than and less than , an abstract relational comparison algorithm is used which, according to the manual , can be summarized as:
number
.toString()
to obtain a representation as a string and compareSo, in the example that you put in your question: There is a numeric element and the other could also be converted to a number without problem, so the evaluation is correct.
Just to add a little more about the behavior of operators and to know what happens with arrays and objects:
The addition operator evaluates if the operands are numeric (or can be converted to a number) to perform an addition, otherwise it will treat (or coerce) them as a string.