In general, we only use big-O notation when n can rise to obscenely large values, because big-O notation describes how the execution time grows as the input grows. For instance, when sorting a list, most of the best algorithms sort in O(n log n) - which means, and only means, that when the list is long enough, that the time it takes to sort it is proportional to n log n. When the list is not long enough, other factors (for instance, any time your algorithm might take to allocate extra space), become significant, and can potentially even take over the running time.
With JavaScript strings, n can indeed get arbitrarily large*, so we say the comparison takes O(n) time. But with JavaScript numbers (which are IEEE 754 double-precision floating point numbers), n has a maximum cap of 64 - 1 for a sign bit, 11 for an exponent, and 53 for significant digits**. Because of this, we know exactly how long it will possibly take for a number comparison to occur, and the best systems we have for comparing numbers of that exact size more or less run the same regardless of how many of those 64 digits each number actually has - hence, comparing these numbers in JavaScript is considered O(1).
*Technically, there is an upper limit because RAM can run out. However, the language doesn't specify a maximum size for strings, and the O(n) part of string comparison dominates the execution time well before that happens.
**By the way, this does mean that numbers in JavaScript can't rise infinitely. Past a certain point, they start throwing away smaller digits (for instance, numbers above 2^53 can only be even, and numbers above 2^54 can only be divisible by 4), and when the number gets large enough, it rounds up to infinity. Conversely, if you divide a number over and over again to make it infinitesimally small, it will eventually round down to zero.