After I found that Javascript common/latest implementations are using String Interning for perfomance boost from here (Do common JavaScript implementations use string interning?)
I thought === for strings would get the constant O(1) time. So I gave a wrong answer to this question (JavaScript string equality performance comparison) since according to the OP of that question it is O(N) - Doubling the string input doubles the time the equality needs.
Can someone please explain why string interning is not used for equality as such (so we have constant time ?):
var str1 = "stringwithmillionchars"; //stored in address 51242
var str2 = "stringwithmillionchars"; //stored in address 12313
the "stringwithmillionchars" would be stored once let's say in address 201012 of memory and both str1 and str2 would be "pointing in this address 201012. This address could theb be determined with some kind of hashing to map to specific locations in memory.
So when doing
"stringwithmillionchars"==="stringwithmillionchars"
would look like
getContentOfAddress(51242)===getContentOfAddress(12313)
or 201012 === 201012
which would take O(1)/constant time
EDIT (NEW) JSPerf seems to show constant time even if the string is 16 times longer?? Please have a look:
str = new String("test");
but I don't know the implications there either.. – Michail Michailidis 19 mins ago