I would like to know if, when comparing two (potentially massive) strings, JavaScript internally starts by comparing their length before looping over the characters.
If not, would that mean doing something along the lines of
if (string1.length !== string2.length || string1 !== string2)
// do something if data changed
should lead to a gain of time, right ? (I am assuming the read-only length
property of a string is computed when the string is set, and not when asked; Not sure if that's actually the case)
For context, I am dealing with massive strings as I am lazily JSON.stringifying arrays of objects received from some API (comparing the latest element only would probably be better but this question is more out of curiosity than anything, please only mind that the strings I would compare would be humongous ^^)
Relevant references ?
https://javascript.info/comparison
Comparing large strings in JavaScript with a hash
Edit
Thank you @RobG in the comment for linking me to ECMA-262's SameValueNonNumber.
In the step definition, step 5 is
SameValueNonNumber ( x, y )
5.If Type(x) is String, then If x and y are exactly the same sequence of code units (same length and same code units at corresponding indices), return true; otherwise, return false.
And I think that answers the question